1 /* $NetBSD: hypervisor.h,v 1.30 2009/07/29 12:02:06 cegger Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Manuel Bouyer. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Manuel Bouyer. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33 /* 34 * 35 * Communication to/from hypervisor. 36 * 37 * Copyright (c) 2002-2004, K A Fraser 38 * 39 * Permission is hereby granted, free of charge, to any person obtaining a copy 40 * of this source file (the "Software"), to deal in the Software without 41 * restriction, including without limitation the rights to use, copy, modify, 42 * merge, publish, distribute, sublicense, and/or sell copies of the Software, 43 * and to permit persons to whom the Software is furnished to do so, subject to 44 * the following conditions: 45 * 46 * The above copyright notice and this permission notice shall be included in 47 * all copies or substantial portions of the Software. 48 * 49 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 50 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 51 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 52 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 53 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 54 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 55 * IN THE SOFTWARE. 56 */ 57 58 59 #ifndef _XEN_HYPERVISOR_H_ 60 #define _XEN_HYPERVISOR_H_ 61 62 #include "opt_xen.h" 63 64 65 struct hypervisor_attach_args { 66 const char *haa_busname; 67 }; 68 69 struct xencons_attach_args { 70 const char *xa_device; 71 }; 72 73 struct xen_npx_attach_args { 74 const char *xa_device; 75 }; 76 77 78 #define u8 uint8_t 79 #define u16 uint16_t 80 #define u32 uint32_t 81 #define u64 uint64_t 82 #define s8 int8_t 83 #define s16 int16_t 84 #define s32 int32_t 85 #define s64 int64_t 86 87 #include <xen/xen3-public/xen.h> 88 #include <xen/xen3-public/sched.h> 89 #include <xen/xen3-public/platform.h> 90 #if __XEN_INTERFACE_VERSION__ < 0x00030204 91 #include <xen/xen3-public/dom0_ops.h> 92 #endif 93 #include <xen/xen3-public/event_channel.h> 94 #include <xen/xen3-public/physdev.h> 95 #include <xen/xen3-public/memory.h> 96 #include <xen/xen3-public/io/netif.h> 97 #include <xen/xen3-public/io/blkif.h> 98 99 #include <machine/hypercalls.h> 100 101 #undef u8 102 #undef u16 103 #undef u32 104 #undef u64 105 #undef s8 106 #undef s16 107 #undef s32 108 #undef s64 109 110 111 112 /* 113 * a placeholder for the start of day information passed up from the hypervisor 114 */ 115 union start_info_union 116 { 117 start_info_t start_info; 118 char padding[512]; 119 }; 120 extern union start_info_union start_info_union; 121 #define xen_start_info (start_info_union.start_info) 122 123 /* For use in guest OSes. */ 124 extern volatile shared_info_t *HYPERVISOR_shared_info; 125 126 127 /* Structural guest handles introduced in 0x00030201. */ 128 #if __XEN_INTERFACE_VERSION__ >= 0x00030201 129 #define xenguest_handle(hnd) (hnd).p 130 #else 131 #define xenguest_handle(hnd) hnd 132 #endif 133 134 /* hypervisor.c */ 135 struct intrframe; 136 void do_hypervisor_callback(struct intrframe *regs); 137 void hypervisor_enable_event(unsigned int); 138 139 /* hypervisor_machdep.c */ 140 void hypervisor_unmask_event(unsigned int); 141 void hypervisor_mask_event(unsigned int); 142 void hypervisor_clear_event(unsigned int); 143 void hypervisor_enable_ipl(unsigned int); 144 void hypervisor_set_ipending(uint32_t, int, int); 145 void hypervisor_machdep_attach(void); 146 147 /* 148 * Force a proper event-channel callback from Xen after clearing the 149 * callback mask. We do this in a very simple manner, by making a call 150 * down into Xen. The pending flag will be checked by Xen on return. 151 */ 152 static __inline void hypervisor_force_callback(void) 153 { 154 (void)HYPERVISOR_xen_version(0, (void*)0); 155 } __attribute__((no_instrument_function)) /* used by mcount */ 156 157 static __inline void 158 hypervisor_notify_via_evtchn(unsigned int port) 159 { 160 evtchn_op_t op; 161 162 op.cmd = EVTCHNOP_send; 163 op.u.send.port = port; 164 (void)HYPERVISOR_event_channel_op(&op); 165 } 166 167 #endif /* _XEN_HYPERVISOR_H_ */ 168