16a306bffSRoger Pau Monné /*****************************************************************************
26a306bffSRoger Pau Monné * x86/xen/xen-os.h
36a306bffSRoger Pau Monné *
46a306bffSRoger Pau Monné * Random collection of macros and definition
56a306bffSRoger Pau Monné *
66a306bffSRoger Pau Monné * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
76a306bffSRoger Pau Monné * All rights reserved.
86a306bffSRoger Pau Monné *
96a306bffSRoger Pau Monné * Permission is hereby granted, free of charge, to any person obtaining a copy
106a306bffSRoger Pau Monné * of this software and associated documentation files (the "Software"), to
116a306bffSRoger Pau Monné * deal in the Software without restriction, including without limitation the
126a306bffSRoger Pau Monné * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
136a306bffSRoger Pau Monné * sell copies of the Software, and to permit persons to whom the Software is
146a306bffSRoger Pau Monné * furnished to do so, subject to the following conditions:
156a306bffSRoger Pau Monné *
166a306bffSRoger Pau Monné * The above copyright notice and this permission notice shall be included in
176a306bffSRoger Pau Monné * all copies or substantial portions of the Software.
186a306bffSRoger Pau Monné *
196a306bffSRoger Pau Monné * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
206a306bffSRoger Pau Monné * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
216a306bffSRoger Pau Monné * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
226a306bffSRoger Pau Monné * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
236a306bffSRoger Pau Monné * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
246a306bffSRoger Pau Monné * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
256a306bffSRoger Pau Monné * DEALINGS IN THE SOFTWARE.
266a306bffSRoger Pau Monné */
276a306bffSRoger Pau Monné
286a306bffSRoger Pau Monné #ifndef _MACHINE_X86_XEN_XEN_OS_H_
296a306bffSRoger Pau Monné #define _MACHINE_X86_XEN_XEN_OS_H_
306a306bffSRoger Pau Monné
31c89f1f12SElliott Mitchell #ifndef _XEN_XEN_OS_H_
32c89f1f12SElliott Mitchell #error "do not #include machine/xen/xen-os.h, #include xen/xen-os.h instead"
33c89f1f12SElliott Mitchell #endif
34c89f1f12SElliott Mitchell
35b6ff9345SElliott Mitchell /* Shared memory needs write-back as its cache attribute for coherency. */
36b6ff9345SElliott Mitchell #define VM_MEMATTR_XEN VM_MEMATTR_WRITE_BACK
37b6ff9345SElliott Mitchell
386a306bffSRoger Pau Monné /* Everything below this point is not included by assembler (.S) files. */
396a306bffSRoger Pau Monné #ifndef __ASSEMBLY__
406a306bffSRoger Pau Monné
4128a78d86SJulien Grall #include <sys/pcpu.h>
4228a78d86SJulien Grall
43b55c0d5fSJulien Grall /* If non-zero, the hypervisor has been configured to use a direct vector */
44b55c0d5fSJulien Grall extern int xen_vector_callback_enabled;
45b55c0d5fSJulien Grall
46c5c26f15SElliott Mitchell /* Signal whether the event channel vector requires EOI at the lapic */
47c5c26f15SElliott Mitchell extern bool xen_evtchn_needs_ack;
48c5c26f15SElliott Mitchell
4969c6eee7SJulien Grall /* tunable for disabling PV disks */
5069c6eee7SJulien Grall extern int xen_disable_pv_disks;
5169c6eee7SJulien Grall
525f700083SJulien Grall /* tunable for disabling PV nics */
535f700083SJulien Grall extern int xen_disable_pv_nics;
545f700083SJulien Grall
554c9e6ad3SElliott Mitchell /* compatibility for accessing xen_ulong_t with atomics */
564c9e6ad3SElliott Mitchell #define atomic_clear_xen_ulong atomic_clear_long
574c9e6ad3SElliott Mitchell #define atomic_set_xen_ulong atomic_set_long
584c9e6ad3SElliott Mitchell #define atomic_readandclear_xen_ulong atomic_readandclear_long
594c9e6ad3SElliott Mitchell #define atomic_testandset_xen_ulong atomic_testandset_long
604c9e6ad3SElliott Mitchell #define atomic_load_acq_xen_ulong atomic_load_acq_long
614c9e6ad3SElliott Mitchell #define atomic_store_rel_xen_ulong atomic_store_rel_long
624c9e6ad3SElliott Mitchell #define atomic_set_xen_ulong atomic_set_long
634c9e6ad3SElliott Mitchell #define atomic_clear_xen_ulong atomic_clear_long
644c9e6ad3SElliott Mitchell
6528a78d86SJulien Grall static inline u_int
XEN_CPUID_TO_VCPUID(u_int cpuid)6628a78d86SJulien Grall XEN_CPUID_TO_VCPUID(u_int cpuid)
6728a78d86SJulien Grall {
6828a78d86SJulien Grall
6928a78d86SJulien Grall return (pcpu_find(cpuid)->pc_vcpu_id);
7028a78d86SJulien Grall }
7128a78d86SJulien Grall
7228a78d86SJulien Grall #define XEN_VCPUID() PCPU_GET(vcpu_id)
7328a78d86SJulien Grall
745f700083SJulien Grall static inline bool
xen_has_percpu_evtchn(void)75ac959cf5SJulien Grall xen_has_percpu_evtchn(void)
76ac959cf5SJulien Grall {
77ac959cf5SJulien Grall
78ac959cf5SJulien Grall return (!xen_hvm_domain() || xen_vector_callback_enabled);
79ac959cf5SJulien Grall }
80ac959cf5SJulien Grall
81ac959cf5SJulien Grall static inline bool
xen_pv_disks_disabled(void)8269c6eee7SJulien Grall xen_pv_disks_disabled(void)
8369c6eee7SJulien Grall {
8469c6eee7SJulien Grall
8569c6eee7SJulien Grall return (xen_hvm_domain() && xen_disable_pv_disks != 0);
8669c6eee7SJulien Grall }
8769c6eee7SJulien Grall
8869c6eee7SJulien Grall static inline bool
xen_pv_nics_disabled(void)895f700083SJulien Grall xen_pv_nics_disabled(void)
905f700083SJulien Grall {
915f700083SJulien Grall
925f700083SJulien Grall return (xen_hvm_domain() && xen_disable_pv_nics != 0);
935f700083SJulien Grall }
945f700083SJulien Grall
95091febc0SRoger Pau Monné bool xen_has_iommu_maps(void);
96091febc0SRoger Pau Monné
97*9a687d1fSRoger Pau Monné /* (Very) early initialization. */
98*9a687d1fSRoger Pau Monné void xen_early_init(void);
99*9a687d1fSRoger Pau Monné
1006a306bffSRoger Pau Monné #endif /* !__ASSEMBLY__ */
1016a306bffSRoger Pau Monné
1026a306bffSRoger Pau Monné #endif /* _MACHINE_X86_XEN_XEN_OS_H_ */
103