]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/xen/xen-os.h
Import device-tree files from Linux 5.13
[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 <xen/interface/xen.h>
44
45 #ifndef __ASSEMBLY__
46 #include <xen/hvm.h>
47 #include <xen/interface/event_channel.h>
48
49 static inline vm_paddr_t
50 xen_get_xenstore_mfn(void)
51 {
52
53         return (hvm_get_parameter(HVM_PARAM_STORE_PFN));
54 }
55
56 static inline evtchn_port_t
57 xen_get_xenstore_evtchn(void)
58 {
59
60         return (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN));
61 }
62
63 static inline vm_paddr_t
64 xen_get_console_mfn(void)
65 {
66
67         return (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN));
68 }
69
70 static inline evtchn_port_t
71 xen_get_console_evtchn(void)
72 {
73
74         return (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN));
75 }
76 #endif
77
78 #include <machine/xen/xen-os.h>
79
80 /* Everything below this point is not included by assembler (.S) files. */
81 #ifndef __ASSEMBLY__
82
83 extern shared_info_t *HYPERVISOR_shared_info;
84
85 extern int xen_disable_pv_disks;
86 extern int xen_disable_pv_nics;
87
88 extern bool xen_suspend_cancelled;
89
90 enum xen_domain_type {
91         XEN_NATIVE,             /* running on bare hardware    */
92         XEN_PV_DOMAIN,          /* running in a PV domain      */
93         XEN_HVM_DOMAIN,         /* running in a Xen hvm domain */
94 };
95
96 extern enum xen_domain_type xen_domain_type;
97
98 static inline int
99 xen_domain(void)
100 {
101         return (xen_domain_type != XEN_NATIVE);
102 }
103
104 static inline int
105 xen_pv_domain(void)
106 {
107         return (xen_domain_type == XEN_PV_DOMAIN);
108 }
109
110 static inline int
111 xen_hvm_domain(void)
112 {
113         return (xen_domain_type == XEN_HVM_DOMAIN);
114 }
115
116 static inline bool
117 xen_initial_domain(void)
118 {
119
120         return (xen_domain() && (hvm_start_flags & SIF_INITDOMAIN) != 0);
121 }
122
123 /*
124  * Based on ofed/include/linux/bitops.h
125  *
126  * Those helpers are prefixed by xen_ because xen-os.h is widely included
127  * and we don't want the other drivers using them.
128  *
129  */
130 #define NBPL (NBBY * sizeof(long))
131
132 static inline bool
133 xen_test_bit(int bit, volatile long *addr)
134 {
135         unsigned long mask = 1UL << (bit % NBPL);
136
137         return !!(atomic_load_acq_long(&addr[bit / NBPL]) & mask);
138 }
139
140 static inline void
141 xen_set_bit(int bit, volatile long *addr)
142 {
143         atomic_set_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
144 }
145
146 static inline void
147 xen_clear_bit(int bit, volatile long *addr)
148 {
149         atomic_clear_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
150 }
151
152 #undef NBPL
153
154 /*
155  * Functions to allocate/free unused memory in order
156  * to map memory from other domains.
157  */
158 struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
159 int xenmem_free(device_t dev, int res_id, struct resource *res);
160
161 /* Debug/emergency function, prints directly to hypervisor console */
162 void xc_printf(const char *, ...) __printflike(1, 2);
163
164 #ifndef xen_mb
165 #define xen_mb() mb()
166 #endif
167 #ifndef xen_rmb
168 #define xen_rmb() rmb()
169 #endif
170 #ifndef xen_wmb
171 #define xen_wmb() wmb()
172 #endif
173
174 #endif /* !__ASSEMBLY__ */
175
176 #endif /* _XEN_XEN_OS_H_ */