1 /* $NetBSD: hypervisor.h,v 1.8 2004/06/14 13:55:52 cl Exp $ */ 2 3 /* 4 * 5 * Communication to/from hypervisor. 6 * 7 * Copyright (c) 2002-2003, K A Fraser 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 29 #ifndef _XEN_HYPERVISOR_H_ 30 #define _XEN_HYPERVISOR_H_ 31 32 33 struct hypervisor_attach_args { 34 const char *haa_busname; 35 }; 36 37 struct xencons_attach_args { 38 const char *xa_device; 39 }; 40 41 struct xen_npx_attach_args { 42 const char *xa_device; 43 }; 44 45 46 #define u16 uint16_t 47 #define u32 uint32_t 48 #define u64 uint64_t 49 50 /* include the hypervisor interface */ 51 #include <sys/systm.h> 52 #include <machine/hypervisor-ifs/block.h> 53 #include <machine/hypervisor-ifs/hypervisor-if.h> 54 #include <machine/hypervisor-ifs/dom0_ops.h> 55 #include <machine/hypervisor-ifs/network.h> 56 #include <machine/hypervisor-ifs/vbd.h> 57 58 #undef u16 59 #undef u32 60 #undef u64 61 62 63 /* 64 * a placeholder for the start of day information passed up from the hypervisor 65 */ 66 union start_info_union 67 { 68 start_info_t start_info; 69 char padding[512]; 70 }; 71 extern union start_info_union start_info_union; 72 #define xen_start_info (start_info_union.start_info) 73 74 75 /* hypervisor.c */ 76 void do_hypervisor_callback(struct trapframe *regs); 77 void hypervisor_enable_event(unsigned int ev); 78 void hypervisor_disable_event(unsigned int ev); 79 void hypervisor_acknowledge_event(unsigned int ev); 80 81 /* 82 * Assembler stubs for hyper-calls. 83 */ 84 85 static inline int HYPERVISOR_set_trap_table(trap_info_t *table) 86 { 87 int ret; 88 __asm__ __volatile__ ( 89 TRAP_INSTR 90 : "=a" (ret) : "0" (__HYPERVISOR_set_trap_table), 91 "b" (table) : "memory" ); 92 93 return ret; 94 } 95 96 static inline int HYPERVISOR_mmu_update(mmu_update_t *req, int count) 97 { 98 int ret; 99 __asm__ __volatile__ ( 100 TRAP_INSTR 101 : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 102 "b" (req), "c" (count) : "memory" ); 103 104 if (__predict_false(ret < 0)) 105 panic("Failed mmu update: %p, %d", req, count); 106 107 return ret; 108 } 109 110 static inline int HYPERVISOR_mmu_update_fail_ok(mmu_update_t *req, int count) 111 { 112 int ret; 113 __asm__ __volatile__ ( 114 TRAP_INSTR 115 : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 116 "b" (req), "c" (count) : "memory" ); 117 118 return ret; 119 } 120 121 static inline int HYPERVISOR_console_write(const char *str, int count) 122 { 123 int ret; 124 __asm__ __volatile__ ( 125 TRAP_INSTR 126 : "=a" (ret) : "0" (__HYPERVISOR_console_write), 127 "b" (str), "c" (count) : "memory" ); 128 129 130 return ret; 131 } 132 133 static inline int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries) 134 { 135 int ret; 136 __asm__ __volatile__ ( 137 TRAP_INSTR 138 : "=a" (ret) : "0" (__HYPERVISOR_set_gdt), 139 "b" (frame_list), "c" (entries) : "memory" ); 140 141 142 return ret; 143 } 144 145 static inline int HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp) 146 { 147 int ret; 148 __asm__ __volatile__ ( 149 TRAP_INSTR 150 : "=a" (ret) : "0" (__HYPERVISOR_stack_switch), 151 "b" (ss), "c" (esp) : "memory" ); 152 153 return ret; 154 } 155 156 static inline int HYPERVISOR_set_callbacks( 157 unsigned long event_selector, unsigned long event_address, 158 unsigned long failsafe_selector, unsigned long failsafe_address) 159 { 160 int ret; 161 __asm__ __volatile__ ( 162 TRAP_INSTR 163 : "=a" (ret) : "0" (__HYPERVISOR_set_callbacks), 164 "b" (event_selector), "c" (event_address), 165 "d" (failsafe_selector), "S" (failsafe_address) : "memory" ); 166 167 return ret; 168 } 169 170 static inline int HYPERVISOR_net_io_op(netop_t *op) 171 { 172 int ret; 173 __asm__ __volatile__ ( 174 TRAP_INSTR 175 : "=a" (ret) : "0" (__HYPERVISOR_net_io_op), 176 "b" (op) : "memory" ); 177 178 return ret; 179 } 180 181 static inline int HYPERVISOR_fpu_taskswitch(void) 182 { 183 int ret; 184 __asm__ __volatile__ ( 185 TRAP_INSTR 186 : "=a" (ret) : "0" (__HYPERVISOR_fpu_taskswitch) : "memory" ); 187 188 return ret; 189 } 190 191 static inline int HYPERVISOR_yield(void) 192 { 193 int ret; 194 __asm__ __volatile__ ( 195 TRAP_INSTR 196 : "=a" (ret) : "0" (__HYPERVISOR_sched_op), 197 "b" (SCHEDOP_yield) : "memory" ); 198 199 return ret; 200 } 201 202 static inline int HYPERVISOR_exit(void) 203 { 204 int ret; 205 __asm__ __volatile__ ( 206 TRAP_INSTR 207 : "=a" (ret) : "0" (__HYPERVISOR_sched_op), 208 "b" (SCHEDOP_exit) : "memory" ); 209 210 return ret; 211 } 212 213 static inline int HYPERVISOR_stop(unsigned long srec) 214 { 215 int ret; 216 /* NB. On suspend, control software expects a suspend record in %esi. */ 217 __asm__ __volatile__ ( 218 TRAP_INSTR 219 : "=a" (ret) : "0" (__HYPERVISOR_sched_op), 220 "b" (SCHEDOP_stop), "S" (srec) : "memory" ); 221 222 return ret; 223 } 224 225 static inline int HYPERVISOR_dom0_op(dom0_op_t *dom0_op) 226 { 227 int ret; 228 dom0_op->interface_version = DOM0_INTERFACE_VERSION; 229 __asm__ __volatile__ ( 230 TRAP_INSTR 231 : "=a" (ret) : "0" (__HYPERVISOR_dom0_op), 232 "b" (dom0_op) : "memory" ); 233 234 return ret; 235 } 236 237 static inline int HYPERVISOR_network_op(void *network_op) 238 { 239 int ret; 240 __asm__ __volatile__ ( 241 TRAP_INSTR 242 : "=a" (ret) : "0" (__HYPERVISOR_network_op), 243 "b" (network_op) : "memory" ); 244 245 return ret; 246 } 247 248 static inline int HYPERVISOR_block_io_op(void * block_io_op) 249 { 250 int ret; 251 __asm__ __volatile__ ( 252 TRAP_INSTR 253 : "=a" (ret) : "0" (__HYPERVISOR_block_io_op), 254 "b" (block_io_op) : "memory" ); 255 256 return ret; 257 } 258 259 static inline int HYPERVISOR_set_debugreg(int reg, unsigned long value) 260 { 261 int ret; 262 __asm__ __volatile__ ( 263 TRAP_INSTR 264 : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg), 265 "b" (reg), "c" (value) : "memory" ); 266 267 return ret; 268 } 269 270 static inline unsigned long HYPERVISOR_get_debugreg(int reg) 271 { 272 unsigned long ret; 273 __asm__ __volatile__ ( 274 TRAP_INSTR 275 : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg), 276 "b" (reg) : "memory" ); 277 278 return ret; 279 } 280 281 static inline int HYPERVISOR_update_descriptor( 282 unsigned long pa, unsigned long word1, unsigned long word2) 283 { 284 int ret; 285 __asm__ __volatile__ ( 286 TRAP_INSTR 287 : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 288 "b" (pa), "c" (word1), "d" (word2) : "memory" ); 289 290 return ret; 291 } 292 293 static inline int HYPERVISOR_set_fast_trap(int idx) 294 { 295 int ret; 296 __asm__ __volatile__ ( 297 TRAP_INSTR 298 : "=a" (ret) : "0" (__HYPERVISOR_set_fast_trap), 299 "b" (idx) : "memory" ); 300 301 return ret; 302 } 303 304 static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op) 305 { 306 int ret; 307 __asm__ __volatile__ ( 308 TRAP_INSTR 309 : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op), 310 "b" (dom_mem_op) : "memory" ); 311 312 return ret; 313 } 314 315 static inline int HYPERVISOR_multicall(void *call_list, int nr_calls) 316 { 317 int ret; 318 __asm__ __volatile__ ( 319 TRAP_INSTR 320 : "=a" (ret) : "0" (__HYPERVISOR_multicall), 321 "b" (call_list), "c" (nr_calls) : "memory" ); 322 323 return ret; 324 } 325 326 static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val) 327 { 328 int ret; 329 __asm__ __volatile__ ( 330 TRAP_INSTR 331 : "=a" (ret) : "0" (__HYPERVISOR_kbd_op), 332 "b" (op), "c" (val) : "memory" ); 333 334 return ret; 335 } 336 337 static inline int HYPERVISOR_update_va_mapping( 338 unsigned long page_nr, unsigned long new_val, unsigned long flags) 339 { 340 int ret; 341 __asm__ __volatile__ ( 342 TRAP_INSTR 343 : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 344 "b" (page_nr), "c" (new_val), "d" (flags) : "memory" ); 345 346 if (__predict_false(ret < 0)) 347 panic("Failed update VA mapping: %08lx, %08lx, %08lx", 348 page_nr, new_val, flags); 349 350 return ret; 351 } 352 353 #endif /* _XEN_HYPERVISOR_H_ */ 354