kvm.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. #ifndef QEMU_KVM_H
  14. #define QEMU_KVM_H
  15. #include <errno.h>
  16. #include "config-host.h"
  17. #include "qemu-queue.h"
  18. #ifdef CONFIG_KVM
  19. #include <linux/kvm.h>
  20. #endif
  21. extern int kvm_allowed;
  22. #if defined CONFIG_KVM || !defined NEED_CPU_H
  23. #define kvm_enabled() (kvm_allowed)
  24. #else
  25. #define kvm_enabled() (0)
  26. #endif
  27. struct kvm_run;
  28. typedef struct KVMCapabilityInfo {
  29. const char *name;
  30. int value;
  31. } KVMCapabilityInfo;
  32. #define KVM_CAP_INFO(CAP) { "KVM_CAP_" stringify(CAP), KVM_CAP_##CAP }
  33. #define KVM_CAP_LAST_INFO { NULL, 0 }
  34. /* external API */
  35. int kvm_init(void);
  36. int kvm_has_sync_mmu(void);
  37. int kvm_has_vcpu_events(void);
  38. int kvm_has_robust_singlestep(void);
  39. int kvm_has_debugregs(void);
  40. int kvm_has_xsave(void);
  41. int kvm_has_xcrs(void);
  42. int kvm_has_many_ioeventfds(void);
  43. #ifdef NEED_CPU_H
  44. int kvm_init_vcpu(CPUState *env);
  45. int kvm_cpu_exec(CPUState *env);
  46. #if !defined(CONFIG_USER_ONLY)
  47. void kvm_setup_guest_memory(void *start, size_t size);
  48. int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
  49. int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
  50. void kvm_flush_coalesced_mmio_buffer(void);
  51. #endif
  52. int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr,
  53. target_ulong len, int type);
  54. int kvm_remove_breakpoint(CPUState *current_env, target_ulong addr,
  55. target_ulong len, int type);
  56. void kvm_remove_all_breakpoints(CPUState *current_env);
  57. int kvm_update_guest_debug(CPUState *env, unsigned long reinject_trap);
  58. #ifndef _WIN32
  59. int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset);
  60. #endif
  61. int kvm_pit_in_kernel(void);
  62. int kvm_irqchip_in_kernel(void);
  63. int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr);
  64. int kvm_on_sigbus(int code, void *addr);
  65. /* internal API */
  66. struct KVMState;
  67. typedef struct KVMState KVMState;
  68. extern KVMState *kvm_state;
  69. int kvm_ioctl(KVMState *s, int type, ...);
  70. int kvm_vm_ioctl(KVMState *s, int type, ...);
  71. int kvm_vcpu_ioctl(CPUState *env, int type, ...);
  72. /* Arch specific hooks */
  73. extern const KVMCapabilityInfo kvm_arch_required_capabilities[];
  74. void kvm_arch_pre_run(CPUState *env, struct kvm_run *run);
  75. void kvm_arch_post_run(CPUState *env, struct kvm_run *run);
  76. int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run);
  77. int kvm_arch_process_async_events(CPUState *env);
  78. int kvm_arch_get_registers(CPUState *env);
  79. /* state subset only touched by the VCPU itself during runtime */
  80. #define KVM_PUT_RUNTIME_STATE 1
  81. /* state subset modified during VCPU reset */
  82. #define KVM_PUT_RESET_STATE 2
  83. /* full state set, modified during initialization or on vmload */
  84. #define KVM_PUT_FULL_STATE 3
  85. int kvm_arch_put_registers(CPUState *env, int level);
  86. int kvm_arch_init(KVMState *s);
  87. int kvm_arch_init_vcpu(CPUState *env);
  88. void kvm_arch_reset_vcpu(CPUState *env);
  89. int kvm_arch_on_sigbus_vcpu(CPUState *env, int code, void *addr);
  90. int kvm_arch_on_sigbus(int code, void *addr);
  91. struct kvm_guest_debug;
  92. struct kvm_debug_exit_arch;
  93. struct kvm_sw_breakpoint {
  94. target_ulong pc;
  95. target_ulong saved_insn;
  96. int use_count;
  97. QTAILQ_ENTRY(kvm_sw_breakpoint) entry;
  98. };
  99. QTAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint);
  100. struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
  101. target_ulong pc);
  102. int kvm_sw_breakpoints_active(CPUState *env);
  103. int kvm_arch_insert_sw_breakpoint(CPUState *current_env,
  104. struct kvm_sw_breakpoint *bp);
  105. int kvm_arch_remove_sw_breakpoint(CPUState *current_env,
  106. struct kvm_sw_breakpoint *bp);
  107. int kvm_arch_insert_hw_breakpoint(target_ulong addr,
  108. target_ulong len, int type);
  109. int kvm_arch_remove_hw_breakpoint(target_ulong addr,
  110. target_ulong len, int type);
  111. void kvm_arch_remove_all_hw_breakpoints(void);
  112. void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg);
  113. bool kvm_arch_stop_on_emulation_error(CPUState *env);
  114. int kvm_check_extension(KVMState *s, unsigned int extension);
  115. uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
  116. uint32_t index, int reg);
  117. void kvm_cpu_synchronize_state(CPUState *env);
  118. void kvm_cpu_synchronize_post_reset(CPUState *env);
  119. void kvm_cpu_synchronize_post_init(CPUState *env);
  120. /* generic hooks - to be moved/refactored once there are more users */
  121. static inline void cpu_synchronize_state(CPUState *env)
  122. {
  123. if (kvm_enabled()) {
  124. kvm_cpu_synchronize_state(env);
  125. }
  126. }
  127. static inline void cpu_synchronize_post_reset(CPUState *env)
  128. {
  129. if (kvm_enabled()) {
  130. kvm_cpu_synchronize_post_reset(env);
  131. }
  132. }
  133. static inline void cpu_synchronize_post_init(CPUState *env)
  134. {
  135. if (kvm_enabled()) {
  136. kvm_cpu_synchronize_post_init(env);
  137. }
  138. }
  139. #if !defined(CONFIG_USER_ONLY)
  140. int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr,
  141. target_phys_addr_t *phys_addr);
  142. #endif
  143. #endif
  144. int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign);
  145. int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);
  146. #endif