xref: /freebsd/sys/x86/include/xen/xen-os.h (revision 8f5406c77f1b7009c36df4e025fd8789a46d33ce)
1 /*****************************************************************************
2  * x86/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 
28 #ifndef _MACHINE_X86_XEN_XEN_OS_H_
29 #define _MACHINE_X86_XEN_XEN_OS_H_
30 
31 #ifndef _XEN_XEN_OS_H_
32 #error "do not #include machine/xen/xen-os.h, #include xen/xen-os.h instead"
33 #endif
34 
35 /* Shared memory needs write-back as its cache attribute for coherency. */
36 #define VM_MEMATTR_XEN VM_MEMATTR_WRITE_BACK
37 
38 /* Everything below this point is not included by assembler (.S) files. */
39 #ifndef __ASSEMBLY__
40 
41 #include <sys/pcpu.h>
42 
43 /* If non-zero, the hypervisor has been configured to use a direct vector */
44 extern int xen_vector_callback_enabled;
45 
46 /* Signal whether the event channel vector requires EOI at the lapic */
47 extern bool xen_evtchn_needs_ack;
48 
49 /* tunable for disabling PV disks */
50 extern int xen_disable_pv_disks;
51 
52 /* tunable for disabling PV nics */
53 extern int xen_disable_pv_nics;
54 
55 /* compatibility for accessing xen_ulong_t with atomics */
56 #define	atomic_clear_xen_ulong		atomic_clear_long
57 #define	atomic_set_xen_ulong		atomic_set_long
58 #define	atomic_readandclear_xen_ulong	atomic_readandclear_long
59 #define	atomic_testandset_xen_ulong	atomic_testandset_long
60 #define	atomic_load_acq_xen_ulong	atomic_load_acq_long
61 #define	atomic_store_rel_xen_ulong	atomic_store_rel_long
62 #define	atomic_set_xen_ulong		atomic_set_long
63 #define	atomic_clear_xen_ulong		atomic_clear_long
64 
65 static inline u_int
XEN_CPUID_TO_VCPUID(u_int cpuid)66 XEN_CPUID_TO_VCPUID(u_int cpuid)
67 {
68 
69 	return (pcpu_find(cpuid)->pc_vcpu_id);
70 }
71 
72 #define	XEN_VCPUID()	PCPU_GET(vcpu_id)
73 
74 static inline bool
xen_has_percpu_evtchn(void)75 xen_has_percpu_evtchn(void)
76 {
77 
78 	return (!xen_hvm_domain() || xen_vector_callback_enabled);
79 }
80 
81 static inline bool
xen_pv_disks_disabled(void)82 xen_pv_disks_disabled(void)
83 {
84 
85 	return (xen_hvm_domain() && xen_disable_pv_disks != 0);
86 }
87 
88 static inline bool
xen_pv_nics_disabled(void)89 xen_pv_nics_disabled(void)
90 {
91 
92 	return (xen_hvm_domain() && xen_disable_pv_nics != 0);
93 }
94 
95 bool xen_has_iommu_maps(void);
96 
97 /* (Very) early initialization. */
98 void xen_early_init(void);
99 
100 #endif /* !__ASSEMBLY__ */
101 
102 #endif /* _MACHINE_X86_XEN_XEN_OS_H_ */
103