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 28 #ifndef _XEN_XEN_OS_H_ 29 #define _XEN_XEN_OS_H_ 30 31 #define __XEN_INTERFACE_VERSION__ 0x00040d00 32 33 #define GRANT_REF_INVALID 0xffffffff 34 35 #ifdef LOCORE 36 #define __ASSEMBLY__ 37 #endif 38 39 #include <contrib/xen/xen.h> 40 41 #ifndef __ASSEMBLY__ 42 #include <xen/hvm.h> 43 #include <contrib/xen/event_channel.h> 44 45 /* 46 * Setup function which needs to be called on each processor by architecture 47 */ 48 extern void xen_setup_vcpu_info(void); 49 50 static inline vm_paddr_t 51 xen_get_xenstore_mfn(void) 52 { 53 54 return (hvm_get_parameter(HVM_PARAM_STORE_PFN)); 55 } 56 57 static inline evtchn_port_t 58 xen_get_xenstore_evtchn(void) 59 { 60 61 return (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN)); 62 } 63 64 static inline vm_paddr_t 65 xen_get_console_mfn(void) 66 { 67 68 return (hvm_get_parameter(HVM_PARAM_CONSOLE_PFN)); 69 } 70 71 static inline evtchn_port_t 72 xen_get_console_evtchn(void) 73 { 74 75 return (hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN)); 76 } 77 78 extern shared_info_t *HYPERVISOR_shared_info; 79 80 extern bool xen_suspend_cancelled; 81 82 static inline bool 83 xen_domain(void) 84 { 85 return (vm_guest == VM_GUEST_XEN); 86 } 87 88 static inline bool 89 xen_pv_domain(void) 90 { 91 return (false); 92 } 93 94 static inline bool 95 xen_hvm_domain(void) 96 { 97 return (vm_guest == VM_GUEST_XEN); 98 } 99 100 static inline bool 101 xen_initial_domain(void) 102 { 103 104 return (xen_domain() && (hvm_start_flags & SIF_INITDOMAIN) != 0); 105 } 106 #endif 107 108 #include <machine/xen/xen-os.h> 109 110 /* Everything below this point is not included by assembler (.S) files. */ 111 #ifndef __ASSEMBLY__ 112 113 /* 114 * Based on ofed/include/linux/bitops.h 115 * 116 * Those helpers are prefixed by xen_ because xen-os.h is widely included 117 * and we don't want the other drivers using them. 118 * 119 */ 120 #define NBPL (NBBY * sizeof(long)) 121 122 static inline bool 123 xen_test_bit(int bit, volatile xen_ulong_t *addr) 124 { 125 unsigned long mask = 1UL << (bit % NBPL); 126 127 return !!(atomic_load_acq_xen_ulong(&addr[bit / NBPL]) & mask); 128 } 129 130 static inline void 131 xen_set_bit(int bit, volatile xen_ulong_t *addr) 132 { 133 atomic_set_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL)); 134 } 135 136 static inline void 137 xen_clear_bit(int bit, volatile xen_ulong_t *addr) 138 { 139 atomic_clear_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL)); 140 } 141 142 #undef NBPL 143 144 /* 145 * Functions to allocate/free unused memory in order 146 * to map memory from other domains. 147 */ 148 struct resource *xenmem_alloc(device_t dev, int *res_id, size_t size); 149 int xenmem_free(device_t dev, int res_id, struct resource *res); 150 151 /* Debug/emergency function, prints directly to hypervisor console */ 152 void xc_printf(const char *, ...) __printflike(1, 2); 153 154 /* 155 * Emergency print function, can be defined per-arch, otherwise defaults to 156 * HYPERVISOR_console_write. Should not be called directly, use xc_printf 157 * instead. 158 */ 159 void xen_emergency_print(const char *str, size_t size); 160 161 #ifndef xen_mb 162 #define xen_mb() mb() 163 #endif 164 #ifndef xen_rmb 165 #define xen_rmb() rmb() 166 #endif 167 #ifndef xen_wmb 168 #define xen_wmb() wmb() 169 #endif 170 171 #endif /* !__ASSEMBLY__ */ 172 173 #endif /* _XEN_XEN_OS_H_ */ 174