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