Home | History | Annotate | Line # | Download | only in include
xen.h revision 1.10
      1 /*	$NetBSD: xen.h,v 1.10 2005/03/09 22:39:20 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 		__insn_barrier();					\
    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 	__insn_barrier();						\
    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 	__insn_barrier(); /* 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 #ifdef MULTIPROCESSOR
    165 #define __LOCK_PREFIX "lock; "
    166 #else
    167 #define __LOCK_PREFIX ""
    168 #endif
    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("xchgl %0,%1"
    176 	    :"=r" (result)
    177 	    :"m" (*ptr), "0" (val)
    178 	    :"memory");
    179 
    180 	return result;
    181 }
    182 
    183 static __inline__ int
    184 x86_atomic_test_and_clear_bit(volatile void *ptr, int bitno)
    185 {
    186         int result;
    187 
    188         __asm __volatile(__LOCK_PREFIX
    189 	    "btrl %2,%1 ;"
    190 	    "sbbl %0,%0"
    191 	    :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
    192 	    :"Ir" (bitno) : "memory");
    193         return result;
    194 }
    195 
    196 static __inline__ int
    197 x86_atomic_test_and_set_bit(volatile void *ptr, int bitno)
    198 {
    199         int result;
    200 
    201         __asm __volatile(__LOCK_PREFIX
    202 	    "btsl %2,%1 ;"
    203 	    "sbbl %0,%0"
    204 	    :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
    205 	    :"Ir" (bitno) : "memory");
    206         return result;
    207 }
    208 
    209 static __inline int
    210 x86_constant_test_bit(const volatile void *ptr, int bitno)
    211 {
    212 	return ((1UL << (bitno & 31)) &
    213 	    (((const volatile uint32_t *) ptr)[bitno >> 5])) != 0;
    214 }
    215 
    216 static __inline int
    217 x86_variable_test_bit(const volatile void *ptr, int bitno)
    218 {
    219 	int result;
    220 
    221 	__asm __volatile(
    222 		"btl %2,%1 ;"
    223 		"sbbl %0,%0"
    224 		:"=r" (result)
    225 		:"m" (*(volatile uint32_t *)(ptr)), "Ir" (bitno));
    226 	return result;
    227 }
    228 
    229 #define x86_atomic_test_bit(ptr, bitno) \
    230 	(__builtin_constant_p(bitno) ? \
    231 	 x86_constant_test_bit((ptr),(bitno)) : \
    232 	 x86_variable_test_bit((ptr),(bitno)))
    233 
    234 static __inline void
    235 x86_atomic_set_bit(volatile void *ptr, int bitno)
    236 {
    237         __asm __volatile(__LOCK_PREFIX
    238 	    "btsl %1,%0"
    239 	    :"=m" (*(volatile uint32_t *)(ptr))
    240 	    :"Ir" (bitno));
    241 }
    242 
    243 static __inline void
    244 x86_atomic_clear_bit(volatile void *ptr, int bitno)
    245 {
    246         __asm __volatile(__LOCK_PREFIX
    247 	    "btrl %1,%0"
    248 	    :"=m" (*(volatile uint32_t *)(ptr))
    249 	    :"Ir" (bitno));
    250 }
    251 
    252 static __inline void
    253 wbinvd(void)
    254 {
    255 	xpq_flush_cache();
    256 }
    257 
    258 #endif /* !__ASSEMBLY__ */
    259 
    260 #endif /* _OS_H_ */
    261