kvm_book3s_asm.h 4.2 KB

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