xref: /freebsd/sys/xen/xen-os.h (revision 4c9e6ad3205a770a029cedc3056790258791e6ba)
176acc41fSJustin T. Gibbs /******************************************************************************
276acc41fSJustin T. Gibbs  * xen/xen-os.h
376acc41fSJustin T. Gibbs  *
476acc41fSJustin T. Gibbs  * Random collection of macros and definition
576acc41fSJustin T. Gibbs  *
676acc41fSJustin T. Gibbs  * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
776acc41fSJustin T. Gibbs  * All rights reserved.
876acc41fSJustin T. Gibbs  *
976acc41fSJustin T. Gibbs  * Permission is hereby granted, free of charge, to any person obtaining a copy
1076acc41fSJustin T. Gibbs  * of this software and associated documentation files (the "Software"), to
1176acc41fSJustin T. Gibbs  * deal in the Software without restriction, including without limitation the
1276acc41fSJustin T. Gibbs  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1376acc41fSJustin T. Gibbs  * sell copies of the Software, and to permit persons to whom the Software is
1476acc41fSJustin T. Gibbs  * furnished to do so, subject to the following conditions:
1576acc41fSJustin T. Gibbs  *
1676acc41fSJustin T. Gibbs  * The above copyright notice and this permission notice shall be included in
1776acc41fSJustin T. Gibbs  * all copies or substantial portions of the Software.
1876acc41fSJustin T. Gibbs  *
1976acc41fSJustin T. Gibbs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2076acc41fSJustin T. Gibbs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2176acc41fSJustin T. Gibbs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2276acc41fSJustin T. Gibbs  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2376acc41fSJustin T. Gibbs  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2476acc41fSJustin T. Gibbs  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2576acc41fSJustin T. Gibbs  * DEALINGS IN THE SOFTWARE.
2676acc41fSJustin T. Gibbs  */
2776acc41fSJustin T. Gibbs 
2876acc41fSJustin T. Gibbs #ifndef _XEN_XEN_OS_H_
2976acc41fSJustin T. Gibbs #define _XEN_XEN_OS_H_
3076acc41fSJustin T. Gibbs 
315489d7e9SRoger Pau Monné #define  __XEN_INTERFACE_VERSION__ 0x00040d00
3276acc41fSJustin T. Gibbs 
3376acc41fSJustin T. Gibbs #define GRANT_REF_INVALID   0xffffffff
3476acc41fSJustin T. Gibbs 
3576acc41fSJustin T. Gibbs #ifdef LOCORE
3676acc41fSJustin T. Gibbs #define __ASSEMBLY__
3776acc41fSJustin T. Gibbs #endif
3876acc41fSJustin T. Gibbs 
39ad7dd514SElliott Mitchell #include <contrib/xen/xen.h>
4076acc41fSJustin T. Gibbs 
41cfa0b7b8SRoger Pau Monné #ifndef __ASSEMBLY__
422117a66aSMitchell Horne #include <xen/hvm.h>
43ad7dd514SElliott Mitchell #include <contrib/xen/event_channel.h>
44cfa0b7b8SRoger Pau Monné 
4520fc5bf7SElliott Mitchell /*
4620fc5bf7SElliott Mitchell  * Setup function which needs to be called on each processor by architecture
4720fc5bf7SElliott Mitchell  */
4820fc5bf7SElliott Mitchell extern void xen_setup_vcpu_info(void);
4920fc5bf7SElliott Mitchell 
50cfa0b7b8SRoger Pau Monné static inline vm_paddr_t
51cfa0b7b8SRoger Pau Monné xen_get_xenstore_mfn(void)
52cfa0b7b8SRoger Pau Monné {
53cfa0b7b8SRoger Pau Monné 
542117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_STORE_PFN));
55cfa0b7b8SRoger Pau Monné }
56cfa0b7b8SRoger Pau Monné 
57cfa0b7b8SRoger Pau Monné static inline evtchn_port_t
58cfa0b7b8SRoger Pau Monné xen_get_xenstore_evtchn(void)
59cfa0b7b8SRoger Pau Monné {
60cfa0b7b8SRoger Pau Monné 
612117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN));
62cfa0b7b8SRoger Pau Monné }
63cfa0b7b8SRoger Pau Monné 
64cfa0b7b8SRoger Pau Monné static inline vm_paddr_t
65cfa0b7b8SRoger Pau Monné xen_get_console_mfn(void)
66cfa0b7b8SRoger Pau Monné {
67cfa0b7b8SRoger Pau Monné 
682117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN));
69cfa0b7b8SRoger Pau Monné }
70cfa0b7b8SRoger Pau Monné 
71cfa0b7b8SRoger Pau Monné static inline evtchn_port_t
72cfa0b7b8SRoger Pau Monné xen_get_console_evtchn(void)
73cfa0b7b8SRoger Pau Monné {
74cfa0b7b8SRoger Pau Monné 
752117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN));
76cfa0b7b8SRoger Pau Monné }
7776acc41fSJustin T. Gibbs 
7876acc41fSJustin T. Gibbs extern shared_info_t *HYPERVISOR_shared_info;
7976acc41fSJustin T. Gibbs 
808dee0e9bSRoger Pau Monné extern bool xen_suspend_cancelled;
818dee0e9bSRoger Pau Monné 
82c7368ccbSElliott Mitchell static inline bool
8376acc41fSJustin T. Gibbs xen_domain(void)
8476acc41fSJustin T. Gibbs {
85c7368ccbSElliott Mitchell 	return (vm_guest == VM_GUEST_XEN);
8676acc41fSJustin T. Gibbs }
8776acc41fSJustin T. Gibbs 
88c7368ccbSElliott Mitchell static inline bool
8976acc41fSJustin T. Gibbs xen_pv_domain(void)
9076acc41fSJustin T. Gibbs {
91c7368ccbSElliott Mitchell 	return (false);
9276acc41fSJustin T. Gibbs }
9376acc41fSJustin T. Gibbs 
94c7368ccbSElliott Mitchell static inline bool
9576acc41fSJustin T. Gibbs xen_hvm_domain(void)
9676acc41fSJustin T. Gibbs {
97c7368ccbSElliott Mitchell 	return (vm_guest == VM_GUEST_XEN);
9876acc41fSJustin T. Gibbs }
9976acc41fSJustin T. Gibbs 
1006f4246bcSRoger Pau Monné static inline bool
1016f4246bcSRoger Pau Monné xen_initial_domain(void)
1026f4246bcSRoger Pau Monné {
103cfa0b7b8SRoger Pau Monné 
1042117a66aSMitchell Horne 	return (xen_domain() && (hvm_start_flags & SIF_INITDOMAIN) != 0);
1056f4246bcSRoger Pau Monné }
106c89f1f12SElliott Mitchell #endif
107c89f1f12SElliott Mitchell 
108c89f1f12SElliott Mitchell #include <machine/xen/xen-os.h>
109c89f1f12SElliott Mitchell 
110c89f1f12SElliott Mitchell /* Everything below this point is not included by assembler (.S) files. */
111c89f1f12SElliott Mitchell #ifndef __ASSEMBLY__
1126f4246bcSRoger Pau Monné 
1130df8b29dSRoger Pau Monné /*
1142f9ec994SRoger Pau Monné  * Based on ofed/include/linux/bitops.h
1152f9ec994SRoger Pau Monné  *
1162f9ec994SRoger Pau Monné  * Those helpers are prefixed by xen_ because xen-os.h is widely included
1172f9ec994SRoger Pau Monné  * and we don't want the other drivers using them.
1182f9ec994SRoger Pau Monné  *
1192f9ec994SRoger Pau Monné  */
1202f9ec994SRoger Pau Monné #define NBPL (NBBY * sizeof(long))
1212f9ec994SRoger Pau Monné 
1222f9ec994SRoger Pau Monné static inline bool
123*4c9e6ad3SElliott Mitchell xen_test_bit(int bit, volatile xen_ulong_t *addr)
1242f9ec994SRoger Pau Monné {
1252f9ec994SRoger Pau Monné 	unsigned long mask = 1UL << (bit % NBPL);
1262f9ec994SRoger Pau Monné 
127*4c9e6ad3SElliott Mitchell 	return !!(atomic_load_acq_xen_ulong(&addr[bit / NBPL]) & mask);
1282f9ec994SRoger Pau Monné }
1292f9ec994SRoger Pau Monné 
1302f9ec994SRoger Pau Monné static inline void
131*4c9e6ad3SElliott Mitchell xen_set_bit(int bit, volatile xen_ulong_t *addr)
1322f9ec994SRoger Pau Monné {
133*4c9e6ad3SElliott Mitchell 	atomic_set_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
1342f9ec994SRoger Pau Monné }
1352f9ec994SRoger Pau Monné 
136f186ed52SRoger Pau Monné static inline void
137*4c9e6ad3SElliott Mitchell xen_clear_bit(int bit, volatile xen_ulong_t *addr)
138f186ed52SRoger Pau Monné {
139*4c9e6ad3SElliott Mitchell 	atomic_clear_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
140f186ed52SRoger Pau Monné }
141f186ed52SRoger Pau Monné 
14289ee6cecSRoger Pau Monné #undef NBPL
1432f9ec994SRoger Pau Monné 
1442f9ec994SRoger Pau Monné /*
1450df8b29dSRoger Pau Monné  * Functions to allocate/free unused memory in order
1460df8b29dSRoger Pau Monné  * to map memory from other domains.
1470df8b29dSRoger Pau Monné  */
1480df8b29dSRoger Pau Monné struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
1490df8b29dSRoger Pau Monné int xenmem_free(device_t dev, int res_id, struct resource *res);
1500df8b29dSRoger Pau Monné 
151c203fa69SRoger Pau Monné /* Debug/emergency function, prints directly to hypervisor console */
152c203fa69SRoger Pau Monné void xc_printf(const char *, ...) __printflike(1, 2);
153c203fa69SRoger Pau Monné 
15476acc41fSJustin T. Gibbs #ifndef xen_mb
15576acc41fSJustin T. Gibbs #define xen_mb() mb()
15676acc41fSJustin T. Gibbs #endif
15776acc41fSJustin T. Gibbs #ifndef xen_rmb
15876acc41fSJustin T. Gibbs #define xen_rmb() rmb()
15976acc41fSJustin T. Gibbs #endif
16076acc41fSJustin T. Gibbs #ifndef xen_wmb
16176acc41fSJustin T. Gibbs #define xen_wmb() wmb()
16276acc41fSJustin T. Gibbs #endif
16376acc41fSJustin T. Gibbs 
16476acc41fSJustin T. Gibbs #endif /* !__ASSEMBLY__ */
16576acc41fSJustin T. Gibbs 
16676acc41fSJustin T. Gibbs #endif /* _XEN_XEN_OS_H_ */
167