kvm_book3s_asm.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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_ASM_H__
  20. #define __ASM_KVM_BOOK3S_ASM_H__
  21. /* XICS ICP register offsets */
  22. #define XICS_XIRR 4
  23. #define XICS_MFRR 0xc
  24. #define XICS_IPI 2 /* interrupt source # for IPIs */
  25. /* LPIDs we support with this build -- runtime limit may be lower */
  26. #define KVMPPC_NR_LPIDS (LPID_RSVD + 1)
  27. /* Maximum number of threads per physical core */
  28. #define MAX_SMT_THREADS 8
  29. /* Maximum number of subcores per physical core */
  30. #define MAX_SUBCORES 4
  31. #ifdef __ASSEMBLY__
  32. #ifdef CONFIG_KVM_BOOK3S_HANDLER
  33. #include <asm/kvm_asm.h>
  34. .macro DO_KVM intno
  35. .if (\intno == BOOK3S_INTERRUPT_SYSTEM_RESET) || \
  36. (\intno == BOOK3S_INTERRUPT_MACHINE_CHECK) || \
  37. (\intno == BOOK3S_INTERRUPT_DATA_STORAGE) || \
  38. (\intno == BOOK3S_INTERRUPT_INST_STORAGE) || \
  39. (\intno == BOOK3S_INTERRUPT_DATA_SEGMENT) || \
  40. (\intno == BOOK3S_INTERRUPT_INST_SEGMENT) || \
  41. (\intno == BOOK3S_INTERRUPT_EXTERNAL) || \
  42. (\intno == BOOK3S_INTERRUPT_EXTERNAL_HV) || \
  43. (\intno == BOOK3S_INTERRUPT_ALIGNMENT) || \
  44. (\intno == BOOK3S_INTERRUPT_PROGRAM) || \
  45. (\intno == BOOK3S_INTERRUPT_FP_UNAVAIL) || \
  46. (\intno == BOOK3S_INTERRUPT_DECREMENTER) || \
  47. (\intno == BOOK3S_INTERRUPT_SYSCALL) || \
  48. (\intno == BOOK3S_INTERRUPT_TRACE) || \
  49. (\intno == BOOK3S_INTERRUPT_PERFMON) || \
  50. (\intno == BOOK3S_INTERRUPT_ALTIVEC) || \
  51. (\intno == BOOK3S_INTERRUPT_VSX)
  52. b kvmppc_trampoline_\intno
  53. kvmppc_resume_\intno:
  54. .endif
  55. .endm
  56. #else
  57. .macro DO_KVM intno
  58. .endm
  59. #endif /* CONFIG_KVM_BOOK3S_HANDLER */
  60. #else /*__ASSEMBLY__ */
  61. struct kvmppc_vcore;
  62. /* Struct used for coordinating micro-threading (split-core) mode changes */
  63. struct kvm_split_mode {
  64. unsigned long rpr;
  65. unsigned long pmmar;
  66. unsigned long ldbar;
  67. u8 subcore_size;
  68. u8 do_nap;
  69. u8 napped[MAX_SMT_THREADS];
  70. struct kvmppc_vcore *vc[MAX_SUBCORES];
  71. /* Bits for changing lpcr on P9 */
  72. unsigned long lpcr_req;
  73. unsigned long lpidr_req;
  74. unsigned long host_lpcr;
  75. u32 do_set;
  76. u32 do_restore;
  77. union {
  78. u32 allphases;
  79. u8 phase[4];
  80. } lpcr_sync;
  81. };
  82. /*
  83. * This struct goes in the PACA on 64-bit processors. It is used
  84. * to store host state that needs to be saved when we enter a guest
  85. * and restored when we exit, but isn't specific to any particular
  86. * guest or vcpu. It also has some scratch fields used by the guest
  87. * exit code.
  88. */
  89. struct kvmppc_host_state {
  90. ulong host_r1;
  91. ulong host_r2;
  92. ulong host_msr;
  93. ulong vmhandler;
  94. ulong scratch0;
  95. ulong scratch1;
  96. ulong scratch2;
  97. u8 in_guest;
  98. u8 restore_hid5;
  99. u8 napping;
  100. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  101. u8 hwthread_req;
  102. u8 hwthread_state;
  103. u8 host_ipi;
  104. u8 ptid; /* thread number within subcore when split */
  105. u8 tid; /* thread number within whole core */
  106. u8 fake_suspend;
  107. struct kvm_vcpu *kvm_vcpu;
  108. struct kvmppc_vcore *kvm_vcore;
  109. void __iomem *xics_phys;
  110. void __iomem *xive_tima_phys;
  111. void __iomem *xive_tima_virt;
  112. u32 saved_xirr;
  113. u64 dabr;
  114. u64 host_mmcr[7]; /* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */
  115. u32 host_pmc[8];
  116. u64 host_purr;
  117. u64 host_spurr;
  118. u64 host_dscr;
  119. u64 dec_expires;
  120. struct kvm_split_mode *kvm_split_mode;
  121. #endif
  122. #ifdef CONFIG_PPC_BOOK3S_64
  123. u64 cfar;
  124. u64 ppr;
  125. u64 host_fscr;
  126. #endif
  127. };
  128. struct kvmppc_book3s_shadow_vcpu {
  129. bool in_use;
  130. ulong gpr[14];
  131. u32 cr;
  132. ulong xer;
  133. ulong ctr;
  134. ulong lr;
  135. ulong pc;
  136. ulong shadow_srr1;
  137. ulong fault_dar;
  138. u32 fault_dsisr;
  139. u32 last_inst;
  140. #ifdef CONFIG_PPC_BOOK3S_32
  141. u32 sr[16]; /* Guest SRs */
  142. struct kvmppc_host_state hstate;
  143. #endif
  144. #ifdef CONFIG_PPC_BOOK3S_64
  145. u8 slb_max; /* highest used guest slb entry */
  146. struct {
  147. u64 esid;
  148. u64 vsid;
  149. } slb[64]; /* guest SLB */
  150. u64 shadow_fscr;
  151. #endif
  152. };
  153. #endif /*__ASSEMBLY__ */
  154. /* Values for kvm_state */
  155. #define KVM_HWTHREAD_IN_KERNEL 0
  156. #define KVM_HWTHREAD_IN_IDLE 1
  157. #define KVM_HWTHREAD_IN_KVM 2
  158. #endif /* __ASM_KVM_BOOK3S_ASM_H__ */