1 /* 2 ** Copyright (c) 2011, Intel Corporation 3 ** 4 ** This software is licensed under the terms of the GNU General Public 5 ** License version 2, as published by the Free Software Foundation, and 6 ** may be copied, distributed, and modified under those terms. 7 ** 8 ** This program is distributed in the hope that it will be useful, 9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ** GNU General Public License for more details. 12 */ 13 14 #ifndef __HAX_UNIX_H 15 #define __HAX_UNIX_H 16 17 #include <sys/types.h> 18 #include <sys/ioctl.h> 19 #include <sys/mman.h> 20 #include <stdarg.h> 21 22 #define HAX_INVALID_FD (-1) 23 static inline int hax_invalid_fd(hax_fd fd) 24 { 25 return fd <= 0; 26 } 27 28 static inline void hax_mod_close(struct hax_state *hax) 29 { 30 close(hax->fd); 31 } 32 33 static inline void hax_close_fd(hax_fd fd) 34 { 35 close(fd); 36 } 37 38 /* HAX model level ioctl */ 39 /* Get API version the HAX driver supports */ 40 #define HAX_IOCTL_VERSION _IOWR(0, 0x20, struct hax_module_version) 41 /* Create VM instance and return the vm_id */ 42 #define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, int) 43 /* Get HAXM capability information */ 44 #define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo) 45 46 /* Pass down a VM_ID, create a VCPU instance for it */ 47 #define HAX_VM_IOCTL_VCPU_CREATE _IOR(0, 0x80, int) 48 /* 49 * Allocate guest memory, the step of allocate guest memory is: 50 * 1. QEMU will allocate the virtual address to cover the guest memory ranges 51 * 2. QEMU passing down the virtual address and length in the 52 * HAX_VM_IOCTL_ALLOC_RAM ioctl through hax_alloc_ram_info structure 53 * 3. HAX driver populate physical memory for the virtual address range, and 54 * lock these physical memory lock, so that they will not be swapped out 55 * 4. HAX driver map the populated physical memory into kernel address space 56 */ 57 #define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info) 58 /* 59 * Setup translation between guest physical address and host physical address 60 */ 61 #define HAX_VM_IOCTL_SET_RAM _IOWR(0, 0x82, struct hax_set_ram_info) 62 63 /* 64 * QEMU notify HAXM driver of the API version currently in use, so that 65 * HAXM driver will not present features that possibly not supported 66 * by QEMU 67 */ 68 #define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION _IOW(0, 0x84, struct hax_qemu_version) 69 70 /* Run the guest in non-root mode */ 71 #define HAX_VCPU_IOCTL_RUN _IO(0, 0xc0) 72 /* Sync QEMU's guest MSR value to HAX driver */ 73 #define HAX_VCPU_IOCTL_SET_MSRS _IOWR(0, 0xc1, struct hax_msr_data) 74 /* Sync HAX driver's guest MSR value to QEMU */ 75 #define HAX_VCPU_IOCTL_GET_MSRS _IOWR(0, 0xc2, struct hax_msr_data) 76 #define HAX_VCPU_IOCTL_SET_FPU _IOW(0, 0xc3, struct fx_layout) 77 #define HAX_VCPU_IOCTL_GET_FPU _IOR(0, 0xc4, struct fx_layout) 78 79 /* Setup HAX tunnel, see structure hax_tunnel comments in hax-interface.h */ 80 #define HAX_VCPU_IOCTL_SETUP_TUNNEL _IOWR(0, 0xc5, struct hax_tunnel_info) 81 /* A interrupt need to be injected into guest */ 82 #define HAX_VCPU_IOCTL_INTERRUPT _IOWR(0, 0xc6, uint32_t) 83 #define HAX_VCPU_SET_REGS _IOWR(0, 0xc7, struct vcpu_state_t) 84 #define HAX_VCPU_GET_REGS _IOWR(0, 0xc8, struct vcpu_state_t) 85 86 #endif /* __HAX_UNIX_H */ 87