xen.h revision 1.9.2.1 1 /* $NetBSD: xen.h,v 1.9.2.1 2004/12/13 17:52:21 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 xenmachmem_init(void);
54 void xenprivcmd_init(void);
55 void xenvfr_init(void);
56
57 void idle_block(void);
58
59 #ifdef XENDEBUG
60 void printk(const char *, ...);
61 void vprintk(const char *, va_list);
62 #endif
63
64 #endif
65
66 #endif /* _XEN_H */
67
68 /******************************************************************************
69 * os.h
70 *
71 * random collection of macros and definition
72 */
73
74 #ifndef _OS_H_
75 #define _OS_H_
76
77 /*
78 * These are the segment descriptors provided for us by the hypervisor.
79 * For now, these are hardwired -- guest OSes cannot update the GDT
80 * or LDT.
81 *
82 * It shouldn't be hard to support descriptor-table frobbing -- let me
83 * know if the BSD or XP ports require flexibility here.
84 */
85
86
87 /*
88 * these are also defined in xen-public/xen.h but can't be pulled in as
89 * they are used in start of day assembly. Need to clean up the .h files
90 * a bit more...
91 */
92
93 #ifndef FLAT_RING1_CS
94 #define FLAT_RING1_CS 0x0819
95 #define FLAT_RING1_DS 0x0821
96 #define FLAT_RING3_CS 0x082b
97 #define FLAT_RING3_DS 0x0833
98 #endif
99
100 #define __KERNEL_CS FLAT_RING1_CS
101 #define __KERNEL_DS FLAT_RING1_DS
102
103 /* Everything below this point is not included by assembler (.S) files. */
104 #ifndef _LOCORE
105
106 /* some function prototypes */
107 void trap_init(void);
108
109
110 /*
111 * STI/CLI equivalents. These basically set and clear the virtual
112 * event_enable flag in the shared_info structure. Note that when
113 * the enable bit is set, there may be pending events to be handled.
114 * We may therefore call into do_hypervisor_callback() directly.
115 */
116
117 #define __save_flags(x) \
118 do { \
119 (x) = HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask; \
120 } while (0)
121
122 #define __restore_flags(x) \
123 do { \
124 shared_info_t *_shared = HYPERVISOR_shared_info; \
125 __insn_barrier(); \
126 if ((_shared->vcpu_data[0].evtchn_upcall_mask = (x)) == 0) { \
127 __insn_barrier(); \
128 if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
129 hypervisor_force_callback(); \
130 } \
131 } while (0)
132
133 #define __cli() \
134 do { \
135 HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask = 1; \
136 __insn_barrier(); \
137 } while (0)
138
139 #define __sti() \
140 do { \
141 shared_info_t *_shared = HYPERVISOR_shared_info; \
142 __insn_barrier(); \
143 _shared->vcpu_data[0].evtchn_upcall_mask = 0; \
144 __insn_barrier(); /* unmask then check (avoid races) */ \
145 if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
146 hypervisor_force_callback(); \
147 } while (0)
148
149 #define cli() __cli()
150 #define sti() __sti()
151 #define save_flags(x) __save_flags(x)
152 #define restore_flags(x) __restore_flags(x)
153 #define save_and_cli(x) do { \
154 __save_flags(x); \
155 __cli(); \
156 } while (/* CONSTCOND */ 0)
157 #define save_and_sti(x) __save_and_sti(x)
158
159 #ifdef MULTIPROCESSOR
160 #define __LOCK_PREFIX "lock; "
161 #else
162 #define __LOCK_PREFIX ""
163 #endif
164
165 static __inline__ uint32_t
166 x86_atomic_xchg(uint32_t *ptr, unsigned long val)
167 {
168 unsigned long result;
169
170 __asm __volatile("xchgl %0,%1"
171 :"=r" (result)
172 :"m" (*ptr), "0" (val)
173 :"memory");
174
175 return result;
176 }
177
178 static __inline__ int
179 x86_atomic_test_and_clear_bit(volatile void *ptr, int bitno)
180 {
181 int result;
182
183 __asm __volatile(__LOCK_PREFIX
184 "btrl %2,%1 ;"
185 "sbbl %0,%0"
186 :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
187 :"Ir" (bitno) : "memory");
188 return result;
189 }
190
191 static __inline__ int
192 x86_atomic_test_and_set_bit(volatile void *ptr, int bitno)
193 {
194 int result;
195
196 __asm __volatile(__LOCK_PREFIX
197 "btsl %2,%1 ;"
198 "sbbl %0,%0"
199 :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
200 :"Ir" (bitno) : "memory");
201 return result;
202 }
203
204 static __inline int
205 x86_constant_test_bit(const volatile void *ptr, int bitno)
206 {
207 return ((1UL << (bitno & 31)) &
208 (((const volatile uint32_t *) ptr)[bitno >> 5])) != 0;
209 }
210
211 static __inline int
212 x86_variable_test_bit(const volatile void *ptr, int bitno)
213 {
214 int result;
215
216 __asm __volatile(
217 "btl %2,%1 ;"
218 "sbbl %0,%0"
219 :"=r" (result)
220 :"m" (*(volatile uint32_t *)(ptr)), "Ir" (bitno));
221 return result;
222 }
223
224 #define x86_atomic_test_bit(ptr, bitno) \
225 (__builtin_constant_p(bitno) ? \
226 x86_constant_test_bit((ptr),(bitno)) : \
227 x86_variable_test_bit((ptr),(bitno)))
228
229 static __inline void
230 x86_atomic_set_bit(volatile void *ptr, int bitno)
231 {
232 __asm __volatile(__LOCK_PREFIX
233 "btsl %1,%0"
234 :"=m" (*(volatile uint32_t *)(ptr))
235 :"Ir" (bitno));
236 }
237
238 static __inline void
239 x86_atomic_clear_bit(volatile void *ptr, int bitno)
240 {
241 __asm __volatile(__LOCK_PREFIX
242 "btrl %1,%0"
243 :"=m" (*(volatile uint32_t *)(ptr))
244 :"Ir" (bitno));
245 }
246
247 #endif /* !__ASSEMBLY__ */
248
249 #endif /* _OS_H_ */
250