xref: /freebsd/sys/xen/xen-os.h (revision baa006f3422719d22da2ea920a5a46b608f47ce2)
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__
42*baa006f3SRoger Pau Monné #include <sys/rman.h>
43*baa006f3SRoger Pau Monné 
442117a66aSMitchell Horne #include <xen/hvm.h>
45ad7dd514SElliott Mitchell #include <contrib/xen/event_channel.h>
46cfa0b7b8SRoger Pau Monné 
4720fc5bf7SElliott Mitchell /*
4820fc5bf7SElliott Mitchell  * Setup function which needs to be called on each processor by architecture
4920fc5bf7SElliott Mitchell  */
5020fc5bf7SElliott Mitchell extern void xen_setup_vcpu_info(void);
5120fc5bf7SElliott Mitchell 
52cfa0b7b8SRoger Pau Monné static inline vm_paddr_t
53cfa0b7b8SRoger Pau Monné xen_get_xenstore_mfn(void)
54cfa0b7b8SRoger Pau Monné {
55cfa0b7b8SRoger Pau Monné 
562117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_STORE_PFN));
57cfa0b7b8SRoger Pau Monné }
58cfa0b7b8SRoger Pau Monné 
59cfa0b7b8SRoger Pau Monné static inline evtchn_port_t
60cfa0b7b8SRoger Pau Monné xen_get_xenstore_evtchn(void)
61cfa0b7b8SRoger Pau Monné {
62cfa0b7b8SRoger Pau Monné 
632117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN));
64cfa0b7b8SRoger Pau Monné }
65cfa0b7b8SRoger Pau Monné 
66cfa0b7b8SRoger Pau Monné static inline vm_paddr_t
67cfa0b7b8SRoger Pau Monné xen_get_console_mfn(void)
68cfa0b7b8SRoger Pau Monné {
69cfa0b7b8SRoger Pau Monné 
702117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN));
71cfa0b7b8SRoger Pau Monné }
72cfa0b7b8SRoger Pau Monné 
73cfa0b7b8SRoger Pau Monné static inline evtchn_port_t
74cfa0b7b8SRoger Pau Monné xen_get_console_evtchn(void)
75cfa0b7b8SRoger Pau Monné {
76cfa0b7b8SRoger Pau Monné 
772117a66aSMitchell Horne 	return (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN));
78cfa0b7b8SRoger Pau Monné }
7976acc41fSJustin T. Gibbs 
8076acc41fSJustin T. Gibbs extern shared_info_t *HYPERVISOR_shared_info;
8176acc41fSJustin T. Gibbs 
828dee0e9bSRoger Pau Monné extern bool xen_suspend_cancelled;
838dee0e9bSRoger Pau Monné 
84c7368ccbSElliott Mitchell static inline bool
8576acc41fSJustin T. Gibbs xen_domain(void)
8676acc41fSJustin T. Gibbs {
87c7368ccbSElliott Mitchell 	return (vm_guest == VM_GUEST_XEN);
8876acc41fSJustin T. Gibbs }
8976acc41fSJustin T. Gibbs 
90c7368ccbSElliott Mitchell static inline bool
9176acc41fSJustin T. Gibbs xen_pv_domain(void)
9276acc41fSJustin T. Gibbs {
93c7368ccbSElliott Mitchell 	return (false);
9476acc41fSJustin T. Gibbs }
9576acc41fSJustin T. Gibbs 
96c7368ccbSElliott Mitchell static inline bool
9776acc41fSJustin T. Gibbs xen_hvm_domain(void)
9876acc41fSJustin T. Gibbs {
99c7368ccbSElliott Mitchell 	return (vm_guest == VM_GUEST_XEN);
10076acc41fSJustin T. Gibbs }
10176acc41fSJustin T. Gibbs 
1026f4246bcSRoger Pau Monné static inline bool
1036f4246bcSRoger Pau Monné xen_initial_domain(void)
1046f4246bcSRoger Pau Monné {
105cfa0b7b8SRoger Pau Monné 
1062117a66aSMitchell Horne 	return (xen_domain() && (hvm_start_flags & SIF_INITDOMAIN) != 0);
1076f4246bcSRoger Pau Monné }
108c89f1f12SElliott Mitchell #endif
109c89f1f12SElliott Mitchell 
110c89f1f12SElliott Mitchell #include <machine/xen/xen-os.h>
111c89f1f12SElliott Mitchell 
112c89f1f12SElliott Mitchell /* Everything below this point is not included by assembler (.S) files. */
113c89f1f12SElliott Mitchell #ifndef __ASSEMBLY__
1146f4246bcSRoger Pau Monné 
1150df8b29dSRoger Pau Monné /*
1162f9ec994SRoger Pau Monné  * Based on ofed/include/linux/bitops.h
1172f9ec994SRoger Pau Monné  *
1182f9ec994SRoger Pau Monné  * Those helpers are prefixed by xen_ because xen-os.h is widely included
1192f9ec994SRoger Pau Monné  * and we don't want the other drivers using them.
1202f9ec994SRoger Pau Monné  *
1212f9ec994SRoger Pau Monné  */
1222f9ec994SRoger Pau Monné #define NBPL (NBBY * sizeof(long))
1232f9ec994SRoger Pau Monné 
1242f9ec994SRoger Pau Monné static inline bool
1254c9e6ad3SElliott Mitchell xen_test_bit(int bit, volatile xen_ulong_t *addr)
1262f9ec994SRoger Pau Monné {
1272f9ec994SRoger Pau Monné 	unsigned long mask = 1UL << (bit % NBPL);
1282f9ec994SRoger Pau Monné 
1294c9e6ad3SElliott Mitchell 	return !!(atomic_load_acq_xen_ulong(&addr[bit / NBPL]) & mask);
1302f9ec994SRoger Pau Monné }
1312f9ec994SRoger Pau Monné 
1322f9ec994SRoger Pau Monné static inline void
1334c9e6ad3SElliott Mitchell xen_set_bit(int bit, volatile xen_ulong_t *addr)
1342f9ec994SRoger Pau Monné {
1354c9e6ad3SElliott Mitchell 	atomic_set_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
1362f9ec994SRoger Pau Monné }
1372f9ec994SRoger Pau Monné 
138f186ed52SRoger Pau Monné static inline void
1394c9e6ad3SElliott Mitchell xen_clear_bit(int bit, volatile xen_ulong_t *addr)
140f186ed52SRoger Pau Monné {
1414c9e6ad3SElliott Mitchell 	atomic_clear_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
142f186ed52SRoger Pau Monné }
143f186ed52SRoger Pau Monné 
14489ee6cecSRoger Pau Monné #undef NBPL
1452f9ec994SRoger Pau Monné 
1462f9ec994SRoger Pau Monné /*
1470df8b29dSRoger Pau Monné  * Functions to allocate/free unused memory in order
1480df8b29dSRoger Pau Monné  * to map memory from other domains.
1490df8b29dSRoger Pau Monné  */
1500df8b29dSRoger Pau Monné struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size);
1510df8b29dSRoger Pau Monné int xenmem_free(device_t dev, int res_id, struct resource *res);
1520df8b29dSRoger Pau Monné 
153c203fa69SRoger Pau Monné /* Debug/emergency function, prints directly to hypervisor console */
154c203fa69SRoger Pau Monné void xc_printf(const char *, ...) __printflike(1, 2);
155c203fa69SRoger Pau Monné 
156399386f1SRoger Pau Monné /*
157399386f1SRoger Pau Monné  * Emergency print function, can be defined per-arch, otherwise defaults to
158399386f1SRoger Pau Monné  * HYPERVISOR_console_write.  Should not be called directly, use xc_printf
159399386f1SRoger Pau Monné  * instead.
160399386f1SRoger Pau Monné  */
161399386f1SRoger Pau Monné void xen_emergency_print(const char *str, size_t size);
162399386f1SRoger Pau Monné 
163*baa006f3SRoger Pau Monné /* Arch-specific helper to init scratch mapping space. */
164*baa006f3SRoger Pau Monné int xen_arch_init_physmem(device_t dev, struct rman *mem);
165*baa006f3SRoger Pau Monné 
16676acc41fSJustin T. Gibbs #ifndef xen_mb
16776acc41fSJustin T. Gibbs #define xen_mb() mb()
16876acc41fSJustin T. Gibbs #endif
16976acc41fSJustin T. Gibbs #ifndef xen_rmb
17076acc41fSJustin T. Gibbs #define xen_rmb() rmb()
17176acc41fSJustin T. Gibbs #endif
17276acc41fSJustin T. Gibbs #ifndef xen_wmb
17376acc41fSJustin T. Gibbs #define xen_wmb() wmb()
17476acc41fSJustin T. Gibbs #endif
17576acc41fSJustin T. Gibbs 
17676acc41fSJustin T. Gibbs #endif /* !__ASSEMBLY__ */
17776acc41fSJustin T. Gibbs 
17876acc41fSJustin T. Gibbs #endif /* _XEN_XEN_OS_H_ */
179