kvm_book3s.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright SUSE Linux Products GmbH 2009
  16. *
  17. * Authors: Alexander Graf <agraf@suse.de>
  18. */
  19. #ifndef __ASM_KVM_BOOK3S_H__
  20. #define __ASM_KVM_BOOK3S_H__
  21. #include <linux/types.h>
  22. #include <linux/kvm_host.h>
  23. #include <asm/kvm_book3s_asm.h>
  24. struct kvmppc_slb {
  25. u64 esid;
  26. u64 vsid;
  27. u64 orige;
  28. u64 origv;
  29. bool valid : 1;
  30. bool Ks : 1;
  31. bool Kp : 1;
  32. bool nx : 1;
  33. bool large : 1; /* PTEs are 16MB */
  34. bool tb : 1; /* 1TB segment */
  35. bool class : 1;
  36. };
  37. struct kvmppc_sr {
  38. u32 raw;
  39. u32 vsid;
  40. bool Ks : 1;
  41. bool Kp : 1;
  42. bool nx : 1;
  43. bool valid : 1;
  44. };
  45. struct kvmppc_bat {
  46. u64 raw;
  47. u32 bepi;
  48. u32 bepi_mask;
  49. u32 brpn;
  50. u8 wimg;
  51. u8 pp;
  52. bool vs : 1;
  53. bool vp : 1;
  54. };
  55. struct kvmppc_sid_map {
  56. u64 guest_vsid;
  57. u64 guest_esid;
  58. u64 host_vsid;
  59. bool valid : 1;
  60. };
  61. #define SID_MAP_BITS 9
  62. #define SID_MAP_NUM (1 << SID_MAP_BITS)
  63. #define SID_MAP_MASK (SID_MAP_NUM - 1)
  64. struct kvmppc_vcpu_book3s {
  65. struct kvm_vcpu vcpu;
  66. struct kvmppc_book3s_shadow_vcpu shadow_vcpu;
  67. struct kvmppc_sid_map sid_map[SID_MAP_NUM];
  68. struct kvmppc_slb slb[64];
  69. struct {
  70. u64 esid;
  71. u64 vsid;
  72. } slb_shadow[64];
  73. u8 slb_shadow_max;
  74. struct kvmppc_sr sr[16];
  75. struct kvmppc_bat ibat[8];
  76. struct kvmppc_bat dbat[8];
  77. u64 hid[6];
  78. u64 gqr[8];
  79. int slb_nr;
  80. u32 dsisr;
  81. u64 sdr1;
  82. u64 hior;
  83. u64 msr_mask;
  84. u64 vsid_first;
  85. u64 vsid_next;
  86. u64 vsid_max;
  87. int context_id;
  88. ulong prog_flags; /* flags to inject when giving a 700 trap */
  89. };
  90. #define CONTEXT_HOST 0
  91. #define CONTEXT_GUEST 1
  92. #define CONTEXT_GUEST_END 2
  93. #define VSID_REAL_DR 0x7ffffffffff00000ULL
  94. #define VSID_REAL_IR 0x7fffffffffe00000ULL
  95. #define VSID_SPLIT_MASK 0x7fffffffffe00000ULL
  96. #define VSID_REAL 0x7fffffffffc00000ULL
  97. #define VSID_BAT 0x7fffffffffb00000ULL
  98. #define VSID_PR 0x8000000000000000ULL
  99. extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
  100. extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
  101. extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end);
  102. extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
  103. extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
  104. extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
  105. extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
  106. extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
  107. extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
  108. extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
  109. extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
  110. extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
  111. extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
  112. extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
  113. bool upper, u32 val);
  114. extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
  115. extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
  116. extern u32 kvmppc_trampoline_lowmem;
  117. extern u32 kvmppc_trampoline_enter;
  118. extern void kvmppc_rmcall(ulong srr0, ulong srr1);
  119. extern void kvmppc_load_up_fpu(void);
  120. extern void kvmppc_load_up_altivec(void);
  121. extern void kvmppc_load_up_vsx(void);
  122. extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst);
  123. extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst);
  124. static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
  125. {
  126. return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
  127. }
  128. static inline ulong dsisr(void)
  129. {
  130. ulong r;
  131. asm ( "mfdsisr %0 " : "=r" (r) );
  132. return r;
  133. }
  134. extern void kvm_return_point(void);
  135. /* Magic register values loaded into r3 and r4 before the 'sc' assembly
  136. * instruction for the OSI hypercalls */
  137. #define OSI_SC_MAGIC_R3 0x113724FA
  138. #define OSI_SC_MAGIC_R4 0x77810F9B
  139. #define INS_DCBZ 0x7c0007ec
  140. #endif /* __ASM_KVM_BOOK3S_H__ */