kvm.h revision 9b3a4b03315af9bcdf282243059e8fd1ce1c5c70
1/* 2 * QEMU KVM support 3 * 4 * Copyright IBM, Corp. 2008 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 * 12 */ 13 14#ifndef QEMU_KVM_H 15#define QEMU_KVM_H 16 17#include "config.h" 18#include "cpu.h" 19#include "qemu/queue.h" 20 21#ifdef CONFIG_KVM 22 23#ifdef TARGET_I386 24extern int kvm_allowed; 25 26#define kvm_enabled() (kvm_allowed) 27#else 28#define kvm_enabled() (0) 29#endif 30 31#else 32#define kvm_enabled() (0) 33#endif 34 35struct kvm_run; 36 37/* external API */ 38 39int kvm_init(int smp_cpus); 40 41int kvm_init_vcpu(CPUOldState *env); 42int kvm_sync_vcpus(void); 43 44int kvm_cpu_exec(CPUOldState *env); 45 46void kvm_set_phys_mem(hwaddr start_addr, 47 ram_addr_t size, 48 ram_addr_t phys_offset); 49 50int kvm_physical_sync_dirty_bitmap(hwaddr start_addr, 51 hwaddr end_addr); 52 53int kvm_log_start(hwaddr phys_addr, ram_addr_t size); 54int kvm_log_stop(hwaddr phys_addr, ram_addr_t size); 55int kvm_set_migration_log(int enable); 56 57int kvm_has_sync_mmu(void); 58 59void kvm_setup_guest_memory(void *start, size_t size); 60 61int kvm_coalesce_mmio_region(hwaddr start, ram_addr_t size); 62int kvm_uncoalesce_mmio_region(hwaddr start, ram_addr_t size); 63 64int kvm_insert_breakpoint(CPUOldState *current_env, target_ulong addr, 65 target_ulong len, int type); 66int kvm_remove_breakpoint(CPUOldState *current_env, target_ulong addr, 67 target_ulong len, int type); 68void kvm_remove_all_breakpoints(CPUOldState *current_env); 69int kvm_update_guest_debug(CPUOldState *env, unsigned long reinject_trap); 70 71/* internal API */ 72 73struct KVMState; 74typedef struct KVMState KVMState; 75 76int kvm_ioctl(KVMState *s, int type, ...); 77 78int kvm_vm_ioctl(KVMState *s, int type, ...); 79 80int kvm_vcpu_ioctl(CPUOldState *env, int type, ...); 81 82int kvm_get_mp_state(CPUOldState *env); 83int kvm_put_mp_state(CPUOldState *env); 84 85/* Arch specific hooks */ 86 87int kvm_arch_post_run(CPUOldState *env, struct kvm_run *run); 88 89int kvm_arch_vcpu_run(CPUOldState *env); 90 91int kvm_arch_handle_exit(CPUOldState *env, struct kvm_run *run); 92 93int kvm_arch_pre_run(CPUOldState *env, struct kvm_run *run); 94 95int kvm_arch_get_registers(CPUOldState *env); 96 97int kvm_arch_put_registers(CPUOldState *env); 98 99int kvm_arch_init(KVMState *s, int smp_cpus); 100 101int kvm_arch_init_vcpu(CPUOldState *env); 102 103struct kvm_guest_debug; 104struct kvm_debug_exit_arch; 105 106struct kvm_sw_breakpoint { 107 target_ulong pc; 108 target_ulong saved_insn; 109 int use_count; 110 QTAILQ_ENTRY(kvm_sw_breakpoint) entry; 111}; 112 113QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); 114 115int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info); 116 117struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUOldState *env, 118 target_ulong pc); 119 120int kvm_sw_breakpoints_active(CPUOldState *env); 121 122int kvm_arch_insert_sw_breakpoint(CPUOldState *current_env, 123 struct kvm_sw_breakpoint *bp); 124int kvm_arch_remove_sw_breakpoint(CPUOldState *current_env, 125 struct kvm_sw_breakpoint *bp); 126int kvm_arch_insert_hw_breakpoint(target_ulong addr, 127 target_ulong len, int type); 128int kvm_arch_remove_hw_breakpoint(target_ulong addr, 129 target_ulong len, int type); 130void kvm_arch_remove_all_hw_breakpoints(void); 131 132void kvm_arch_update_guest_debug(CPUOldState *env, struct kvm_guest_debug *dbg); 133 134int kvm_check_extension(KVMState *s, unsigned int extension); 135 136uint32_t kvm_arch_get_supported_cpuid(CPUOldState *env, uint32_t function, 137 int reg); 138 139/* generic hooks - to be moved/refactored once there are more users */ 140#ifdef CONFIG_HAX 141void hax_vcpu_sync_state(CPUOldState *env, int modified); 142#endif 143static inline void cpu_synchronize_state(CPUOldState *env, int modified) 144{ 145 if (kvm_enabled()) { 146 if (modified) 147 kvm_arch_put_registers(env); 148 else 149 kvm_arch_get_registers(env); 150 } 151#ifdef CONFIG_HAX 152 hax_vcpu_sync_state(env, modified); 153#endif 154} 155 156int kvm_get_sregs(CPUOldState *env); 157 158 159#endif 160