summaryrefslogtreecommitdiff
path: root/sys/arch/xen/include/xen.h
blob: 2e56cdbe88b95169d145be7a3ab37db0e7d67921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*	$NetBSD: xen.h,v 1.48 2023/03/24 12:28:42 bouyer Exp $	*/

/*
 *
 * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */


#ifndef _XEN_H
#define _XEN_H

#ifdef _KERNEL_OPT
#include "opt_xen.h"
#endif


#ifndef _LOCORE

#include <machine/cpufunc.h>

struct xen_netinfo {
	uint32_t xi_ifno;
	char *xi_root;
	uint32_t xi_ip[5];
};

union xen_cmdline_parseinfo {
	char			xcp_bootdev[144];
	struct xen_netinfo	xcp_netinfo;
	char			xcp_console[16];
	char			xcp_pcidevs[64];
};

#define	XEN_PARSE_BOOTDEV	0
#define	XEN_PARSE_NETINFO	1
#define	XEN_PARSE_CONSOLE	2
#define	XEN_PARSE_BOOTFLAGS	3
#define	XEN_PARSE_PCIBACK	4

void	xen_parse_cmdline(int, union xen_cmdline_parseinfo *);

void	xenconscn_attach(void);

int 	xen_pvh_consinit(void);

void	xenprivcmd_init(void);

void	xbdback_init(void);
void	xennetback_init(void);
void	xen_shm_init(void);

void	xenevt_event(int);
void	xenevt_setipending(int, int);
void	xenevt_notify(void);

/* xen_machdep.c */
void	sysctl_xen_suspend_setup(void);

#include <sys/stdarg.h>
void printk(const char *, ...);

#endif

#endif /* _XEN_H */

/******************************************************************************
 * os.h
 * 
 * random collection of macros and definition
 */

#ifndef _OS_H_
#define _OS_H_

/*
 * These are the segment descriptors provided for us by the hypervisor.
 * For now, these are hardwired -- guest OSes cannot update the GDT
 * or LDT.
 * 
 * It shouldn't be hard to support descriptor-table frobbing -- let me 
 * know if the BSD or XP ports require flexibility here.
 */


/*
 * these are also defined in xen-public/xen.h but can't be pulled in as
 * they are used in start of day assembly. Need to clean up the .h files
 * a bit more...
 */

#ifndef FLAT_RING1_CS
#define FLAT_RING1_CS 0xe019    /* GDT index 259 */
#define FLAT_RING1_DS 0xe021    /* GDT index 260 */
#define FLAT_RING1_SS 0xe021    /* GDT index 260 */
#define FLAT_RING3_CS 0xe02b    /* GDT index 261 */
#define FLAT_RING3_DS 0xe033    /* GDT index 262 */
#define FLAT_RING3_SS 0xe033    /* GDT index 262 */
#endif

#define __KERNEL_CS        FLAT_RING1_CS
#define __KERNEL_DS        FLAT_RING1_DS

/* Everything below this point is not included by assembler (.S) files. */
#ifndef _LOCORE

/* Version Specific Glue */
#if __XEN_INTERFACE_VERSION__ >= 0x00030203
#define console_mfn    console.domU.mfn
#define console_evtchn console.domU.evtchn
#endif

/* some function prototypes */
void trap_init(void);
void xpq_flush_cache(void);

#define xendomain_is_dom0()		(xen_start_info.flags & SIF_INITDOMAIN)
#define xendomain_is_privileged()	(xen_start_info.flags & SIF_PRIVILEGED)

/*
 * always assume we're on multiprocessor. We don't know how many CPU the
 * underlying hardware has.
 */
#define __LOCK_PREFIX "lock; "

#define XATOMIC_T u_long
#ifdef __x86_64__
#define LONG_SHIFT 6
#define LONG_MASK 63
#else /* __x86_64__ */
#define LONG_SHIFT 5
#define LONG_MASK 31
#endif /* __x86_64__ */

#define xen_ffs __builtin_ffsl

static __inline XATOMIC_T
xen_atomic_xchg(volatile XATOMIC_T *ptr, unsigned long val)
{
	unsigned long result;

	__asm volatile(__LOCK_PREFIX
#ifdef __x86_64__
	    "xchgq %0,%1"
#else
	    "xchgl %0,%1"
#endif
	    :"=r" (result)
	    :"m" (*ptr), "0" (val)
	    :"memory");

	return result;
}

static __inline void
xen_atomic_setbits_l (volatile XATOMIC_T *ptr, unsigned long bits) {  
#ifdef __x86_64__
	__asm volatile("lock ; orq %1,%0" :  "=m" (*ptr) : "ir" (bits));
#else
	__asm volatile("lock ; orl %1,%0" :  "=m" (*ptr) : "ir" (bits));
#endif
}
     
static __inline void
xen_atomic_clearbits_l (volatile XATOMIC_T *ptr, unsigned long bits) {  
#ifdef __x86_64__
	__asm volatile("lock ; andq %1,%0" :  "=m" (*ptr) : "ir" (~bits));
#else
	__asm volatile("lock ; andl %1,%0" :  "=m" (*ptr) : "ir" (~bits));
#endif
}

static __inline XATOMIC_T
xen_atomic_test_and_clear_bit(volatile void *ptr, unsigned long bitno)
{
	long result;

	__asm volatile(__LOCK_PREFIX
#ifdef __x86_64__
	    "btrq %2,%1 ;"
	    "sbbq %0,%0"
#else
	    "btrl %2,%1 ;"
	    "sbbl %0,%0"
#endif
	    :"=r" (result), "=m" (*(volatile XATOMIC_T *)(ptr))
	    :"Ir" (bitno) : "memory");
	return result;
}

static __inline XATOMIC_T
xen_atomic_test_and_set_bit(volatile void *ptr, unsigned long bitno)
{
	long result;

	__asm volatile(__LOCK_PREFIX
#ifdef __x86_64__
	    "btsq %2,%1 ;"
	    "sbbq %0,%0"
#else
	    "btsl %2,%1 ;"
	    "sbbl %0,%0"
#endif
	    :"=r" (result), "=m" (*(volatile XATOMIC_T *)(ptr))
	    :"Ir" (bitno) : "memory");
	return result;
}

static __inline int
xen_constant_test_bit(const volatile void *ptr, unsigned long bitno)
{
	return ((1UL << (bitno & LONG_MASK)) &
	    (((const volatile XATOMIC_T *) ptr)[bitno >> LONG_SHIFT])) != 0;
}

static __inline XATOMIC_T
xen_variable_test_bit(const volatile void *ptr, unsigned long bitno)
{
	long result;
    
	__asm volatile(
#ifdef __x86_64__
		"btq %2,%1 ;"
		"sbbq %0,%0"
#else
		"btl %2,%1 ;"
		"sbbl %0,%0"
#endif
		:"=r" (result)
		:"m" (*(const volatile XATOMIC_T *)(ptr)), "Ir" (bitno));
	return result;
}

#define xen_atomic_test_bit(ptr, bitno) \
	(__builtin_constant_p(bitno) ? \
	 xen_constant_test_bit((ptr),(bitno)) : \
	 xen_variable_test_bit((ptr),(bitno)))

static __inline void
xen_atomic_set_bit(volatile void *ptr, unsigned long bitno)
{
	__asm volatile(__LOCK_PREFIX
#ifdef __x86_64__
	    "btsq %1,%0"
#else
	    "btsl %1,%0"
#endif
	    :"=m" (*(volatile XATOMIC_T *)(ptr))
	    :"Ir" (bitno));
}

static __inline void
xen_atomic_clear_bit(volatile void *ptr, unsigned long bitno)
{
	__asm volatile(__LOCK_PREFIX
#ifdef __x86_64__
	    "btrq %1,%0"
#else
	    "btrl %1,%0"
#endif
	    :"=m" (*(volatile XATOMIC_T *)(ptr))
	    :"Ir" (bitno));
}

#undef XATOMIC_T

void	wbinvd(void);

#include <xen/include/public/features.h>
#include <sys/systm.h>

extern bool xen_feature_tables[];
void xen_init_features(void);
static __inline bool
xen_feature(int f)
{
	KASSERT(f < XENFEAT_NR_SUBMAPS * 32);
	return xen_feature_tables[f];
}

void xen_bootconf(void);

#endif /* !__ASSEMBLY__ */

#endif /* _OS_H_ */