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