x86.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef ARCH_X86_KVM_X86_H
  2. #define ARCH_X86_KVM_X86_H
  3. #include <linux/kvm_host.h>
  4. #include "kvm_cache_regs.h"
  5. static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
  6. {
  7. vcpu->arch.exception.pending = false;
  8. }
  9. static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector,
  10. bool soft)
  11. {
  12. vcpu->arch.interrupt.pending = true;
  13. vcpu->arch.interrupt.soft = soft;
  14. vcpu->arch.interrupt.nr = vector;
  15. }
  16. static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
  17. {
  18. vcpu->arch.interrupt.pending = false;
  19. }
  20. static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)
  21. {
  22. return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending ||
  23. vcpu->arch.nmi_injected;
  24. }
  25. static inline bool kvm_exception_is_soft(unsigned int nr)
  26. {
  27. return (nr == BP_VECTOR) || (nr == OF_VECTOR);
  28. }
  29. struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
  30. u32 function, u32 index);
  31. static inline bool is_protmode(struct kvm_vcpu *vcpu)
  32. {
  33. return kvm_read_cr0_bits(vcpu, X86_CR0_PE);
  34. }
  35. static inline int is_long_mode(struct kvm_vcpu *vcpu)
  36. {
  37. #ifdef CONFIG_X86_64
  38. return vcpu->arch.efer & EFER_LMA;
  39. #else
  40. return 0;
  41. #endif
  42. }
  43. static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)
  44. {
  45. return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu;
  46. }
  47. static inline int is_pae(struct kvm_vcpu *vcpu)
  48. {
  49. return kvm_read_cr4_bits(vcpu, X86_CR4_PAE);
  50. }
  51. static inline int is_pse(struct kvm_vcpu *vcpu)
  52. {
  53. return kvm_read_cr4_bits(vcpu, X86_CR4_PSE);
  54. }
  55. static inline int is_paging(struct kvm_vcpu *vcpu)
  56. {
  57. return kvm_read_cr0_bits(vcpu, X86_CR0_PG);
  58. }
  59. static inline u32 bit(int bitno)
  60. {
  61. return 1 << (bitno & 31);
  62. }
  63. void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
  64. void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
  65. int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
  66. void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
  67. #endif