]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/xen/xen-os.h
mips: for pointers replace 0 with NULL.
[FreeBSD/FreeBSD.git] / sys / xen / xen-os.h
1 /******************************************************************************
2  * xen/xen-os.h
3  * 
4  * Random collection of macros and definition
5  *
6  * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
7  * All rights reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to
11  * deal in the Software without restriction, including without limitation the
12  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13  * sell copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  * 
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  * 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
25  * DEALINGS IN THE SOFTWARE.
26  *
27  * $FreeBSD$
28  */
29
30 #ifndef _XEN_XEN_OS_H_
31 #define _XEN_XEN_OS_H_
32
33 #if !defined(__XEN_INTERFACE_VERSION__)  
34 #define  __XEN_INTERFACE_VERSION__ 0x00030208
35 #endif  
36
37 #define GRANT_REF_INVALID   0xffffffff
38
39 #ifdef LOCORE
40 #define __ASSEMBLY__
41 #endif
42
43 #include <machine/xen/xen-os.h>
44
45 #include <xen/interface/xen.h>
46
47 /* Everything below this point is not included by assembler (.S) files. */
48 #ifndef __ASSEMBLY__
49
50 extern shared_info_t *HYPERVISOR_shared_info;
51 extern start_info_t *HYPERVISOR_start_info;
52
53 /* XXX: we need to get rid of this and use HYPERVISOR_start_info directly */
54 extern char *console_page;
55
56 extern int xen_disable_pv_disks;
57 extern int xen_disable_pv_nics;
58
59 enum xen_domain_type {
60         XEN_NATIVE,             /* running on bare hardware    */
61         XEN_PV_DOMAIN,          /* running in a PV domain      */
62         XEN_HVM_DOMAIN,         /* running in a Xen hvm domain */
63 };
64
65 extern enum xen_domain_type xen_domain_type;
66
67 static inline int
68 xen_domain(void)
69 {
70         return (xen_domain_type != XEN_NATIVE);
71 }
72
73 static inline int
74 xen_pv_domain(void)
75 {
76         return (xen_domain_type == XEN_PV_DOMAIN);
77 }
78
79 static inline int
80 xen_hvm_domain(void)
81 {
82         return (xen_domain_type == XEN_HVM_DOMAIN);
83 }
84
85 static inline bool
86 xen_initial_domain(void)
87 {
88         return (xen_domain() && HYPERVISOR_start_info != NULL &&
89             (HYPERVISOR_start_info->flags & SIF_INITDOMAIN) != 0);
90 }
91
92 /*
93  * Based on ofed/include/linux/bitops.h
94  *
95  * Those helpers are prefixed by xen_ because xen-os.h is widely included
96  * and we don't want the other drivers using them.
97  *
98  */
99 #define NBPL (NBBY * sizeof(long))
100
101 static inline bool
102 xen_test_bit(int bit, volatile long *addr)
103 {
104         unsigned long mask = 1UL << (bit % NBPL);
105
106         return !!(atomic_load_acq_long(&addr[bit / NBPL]) & mask);
107 }
108
109 static inline void
110 xen_set_bit(int bit, volatile long *addr)
111 {
112         atomic_set_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
113 }
114
115 static inline void
116 xen_clear_bit(int bit, volatile long *addr)
117 {
118         atomic_clear_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
119 }
120
121 #undef NPBL
122
123 /*
124  * Functions to allocate/free unused memory in order
125  * to map memory from other domains.
126  */
127 struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
128 int xenmem_free(device_t dev, int res_id, struct resource *res);
129
130 /* Debug/emergency function, prints directly to hypervisor console */
131 void xc_printf(const char *, ...) __printflike(1, 2);
132
133 #ifndef xen_mb
134 #define xen_mb() mb()
135 #endif
136 #ifndef xen_rmb
137 #define xen_rmb() rmb()
138 #endif
139 #ifndef xen_wmb
140 #define xen_wmb() wmb()
141 #endif
142
143 #endif /* !__ASSEMBLY__ */
144
145 #endif /* _XEN_XEN_OS_H_ */