aboutsummaryrefslogtreecommitdiffstats
path: root/netbsd-2.0-xen-sparse/sys/arch/xen/include/xen.h
blob: 274dad8410aef3f9180f2343d18e2d8268f177a7 (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
/*	$NetBSD: xen.h,v 1.1.2.2 2004/06/17 09:23:19 tron 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

#ifndef _LOCORE

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

union xen_cmdline_parseinfo {
	char			xcp_bootdev[16]; /* sizeof(dv_xname) */
	struct xen_netinfo	xcp_netinfo;
	char			xcp_console[16];
};

#define	XEN_PARSE_BOOTDEV	0
#define	XEN_PARSE_NETINFO	1
#define	XEN_PARSE_CONSOLE	2

void	xen_parse_cmdline(int, union xen_cmdline_parseinfo *);

void	xenconscn_attach(void);

void	xenmachmem_init(void);
void	xenprivcmd_init(void);
void	xenvfr_init(void);

void	idle_block(void);

#ifdef XENDEBUG
void printk(const char *, ...);
void vprintk(const char *, va_list);
#endif

#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 hypervisor-if.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		0x0819
#define FLAT_RING1_DS		0x0821
#define FLAT_RING3_CS		0x082b
#define FLAT_RING3_DS		0x0833
#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

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


/*
 * STI/CLI equivalents. These basically set and clear the virtual
 * event_enable flag in the shared_info structure. Note that when
 * the enable bit is set, there may be pending events to be handled.
 * We may therefore call into do_hypervisor_callback() directly.
 */

#define __save_flags(x)							\
do {									\
	(x) = HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask;	\
} while (0)

#define __restore_flags(x)						\
do {									\
	shared_info_t *_shared = HYPERVISOR_shared_info;		\
	__insn_barrier();						\
	if ((_shared->vcpu_data[0].evtchn_upcall_mask = (x)) == 0) {	\
		__insn_barrier();					\
		if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
			hypervisor_force_callback();			\
	}								\
} while (0)

#define __cli()								\
do {									\
	HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask = 1;	\
	__insn_barrier();						\
} while (0)

#define __sti()								\
do {									\
	shared_info_t *_shared = HYPERVISOR_shared_info;		\
	__insn_barrier();						\
	_shared->vcpu_data[0].evtchn_upcall_mask = 0;			\
	__insn_barrier(); /* unmask then check (avoid races) */		\
	if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
		hypervisor_force_callback();				\
} while (0)

#define cli()			__cli()
#define sti()			__sti()
#define save_flags(x)		__save_flags(x)
#define restore_flags(x)	__restore_flags(x)
#define save_and_cli(x)	do {					\
	__save_flags(x);					\
	__cli();						\
} while (/* CONSTCOND */ 0)
#define save_and_sti(x)		__save_and_sti(x)

#ifdef MULTIPROCESSOR
#define __LOCK_PREFIX "lock; "
#else
#define __LOCK_PREFIX ""
#endif

static __inline__ uint32_t
x86_atomic_xchg(uint32_t *ptr, unsigned long val)
{
	unsigned long result;

        __asm __volatile("xchgl %0,%1"
	    :"=r" (result)
	    :"m" (*ptr), "0" (val)
	    :"memory");

	return result;
}

static __inline__ int
x86_atomic_test_and_clear_bit(volatile void *ptr, int bitno)
{
        int result;

        __asm __volatile(__LOCK_PREFIX
	    "btrl %2,%1 ;"
	    "sbbl %0,%0"
	    :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
	    :"Ir" (bitno) : "memory");
        return result;
}

static __inline__ int
x86_atomic_test_and_set_bit(volatile void *ptr, int bitno)
{
        int result;

        __asm __volatile(__LOCK_PREFIX
	    "btsl %2,%1 ;"
	    "sbbl %0,%0"
	    :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
	    :"Ir" (bitno) : "memory");
        return result;
}

static __inline int
x86_constant_test_bit(const volatile void *ptr, int bitno)
{
	return ((1UL << (bitno & 31)) &
	    (((const volatile uint32_t *) ptr)[bitno >> 5])) != 0;
}

static __inline int
x86_variable_test_bit(const volatile void *ptr, int bitno)
{
	int result;
    
	__asm __volatile(
		"btl %2,%1 ;"
		"sbbl %0,%0"
		:"=r" (result)
		:"m" (*(volatile uint32_t *)(ptr)), "Ir" (bitno));
	return result;
}

#define x86_atomic_test_bit(ptr, bitno) \
	(__builtin_constant_p(bitno) ? \
	 x86_constant_test_bit((ptr),(bitno)) : \
	 x86_variable_test_bit((ptr),(bitno)))

static __inline void
x86_atomic_set_bit(volatile void *ptr, int bitno)
{
        __asm __volatile(__LOCK_PREFIX
	    "btsl %1,%0"
	    :"=m" (*(volatile uint32_t *)(ptr))
	    :"Ir" (bitno));
}

static __inline void
x86_atomic_clear_bit(volatile void *ptr, int bitno)
{
        __asm __volatile(__LOCK_PREFIX
	    "btrl %1,%0"
	    :"=m" (*(volatile uint32_t *)(ptr))
	    :"Ir" (bitno));
}

#endif /* !__ASSEMBLY__ */

#endif /* _OS_H_ */