Home | History | Annotate | Download | only in sysemu
      1 /*
      2  * QEMU KVM support
      3  *
      4  * Copyright IBM, Corp. 2008
      5  *
      6  * Authors:
      7  *  Anthony Liguori   <aliguori (at) 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
     24 extern 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 
     35 struct kvm_run;
     36 
     37 /* external API */
     38 
     39 int kvm_init(int smp_cpus);
     40 
     41 int kvm_init_vcpu(CPUState *env);
     42 int kvm_sync_vcpus(void);
     43 
     44 int kvm_cpu_exec(CPUState *env);
     45 
     46 void kvm_set_phys_mem(hwaddr start_addr,
     47                       ram_addr_t size,
     48                       ram_addr_t phys_offset);
     49 
     50 int kvm_physical_sync_dirty_bitmap(hwaddr start_addr,
     51                                    hwaddr end_addr);
     52 
     53 int kvm_log_start(hwaddr phys_addr, ram_addr_t size);
     54 int kvm_log_stop(hwaddr phys_addr, ram_addr_t size);
     55 int kvm_set_migration_log(int enable);
     56 
     57 int kvm_has_sync_mmu(void);
     58 
     59 void kvm_setup_guest_memory(void *start, size_t size);
     60 
     61 int kvm_coalesce_mmio_region(hwaddr start, ram_addr_t size);
     62 int kvm_uncoalesce_mmio_region(hwaddr start, ram_addr_t size);
     63 
     64 int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,
     65                           target_ulong len, int type);
     66 int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr,
     67                           target_ulong len, int type);
     68 void kvm_remove_all_breakpoints(CPUState *current_env);
     69 int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
     70 
     71 /* internal API */
     72 
     73 struct KVMState;
     74 typedef struct KVMState KVMState;
     75 
     76 int kvm_ioctl(KVMState *s, int type, ...);
     77 
     78 int kvm_vm_ioctl(KVMState *s, int type, ...);
     79 
     80 int kvm_vcpu_ioctl(CPUState *env, int type, ...);
     81 
     82 int kvm_get_mp_state(CPUState *env);
     83 int kvm_put_mp_state(CPUState *env);
     84 
     85 /* Arch specific hooks */
     86 
     87 int kvm_arch_post_run(CPUState *env, struct kvm_run *run);
     88 
     89 int kvm_arch_vcpu_run(CPUState *env);
     90 
     91 int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run);
     92 
     93 int kvm_arch_pre_run(CPUState *env, struct kvm_run *run);
     94 
     95 int kvm_arch_get_registers(CPUState *env);
     96 
     97 int kvm_arch_put_registers(CPUState *env);
     98 
     99 int kvm_arch_init(KVMState *s, int smp_cpus);
    100 
    101 int kvm_arch_init_vcpu(CPUState *env);
    102 
    103 struct kvm_guest_debug;
    104 struct kvm_debug_exit_arch;
    105 
    106 struct 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 
    113 QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);
    114 
    115 int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info);
    116 
    117 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
    118                                                  target_ulong pc);
    119 
    120 int kvm_sw_breakpoints_active(CPUState *env);
    121 
    122 int kvm_arch_insert_sw_breakpoint(CPUState *current_env,
    123                                   struct kvm_sw_breakpoint *bp);
    124 int kvm_arch_remove_sw_breakpoint(CPUState *current_env,
    125                                   struct kvm_sw_breakpoint *bp);
    126 int kvm_arch_insert_hw_breakpoint(target_ulong addr,
    127                                   target_ulong len, int type);
    128 int kvm_arch_remove_hw_breakpoint(target_ulong addr,
    129                                   target_ulong len, int type);
    130 void kvm_arch_remove_all_hw_breakpoints(void);
    131 
    132 void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg);
    133 
    134 int kvm_check_extension(KVMState *s, unsigned int extension);
    135 
    136 uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
    137                                       int reg);
    138 
    139 /* generic hooks - to be moved/refactored once there are more users */
    140 #ifdef CONFIG_HAX
    141 void hax_vcpu_sync_state(CPUState *cpu, int modified);
    142 #endif
    143 static inline void cpu_synchronize_state(CPUState *cpu, int modified)
    144 {
    145     if (kvm_enabled()) {
    146         if (modified)
    147             kvm_arch_put_registers(cpu);
    148         else
    149             kvm_arch_get_registers(cpu);
    150     }
    151 #ifdef CONFIG_HAX
    152     hax_vcpu_sync_state(cpu, modified);
    153 #endif
    154 }
    155 
    156 int kvm_get_sregs(CPUState *env);
    157 
    158 
    159 #endif
    160