exception-64e.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Definitions for use by exception code on Book3-E
  4. *
  5. * Copyright (C) 2008 Ben. Herrenschmidt ([email protected]), IBM Corp.
  6. */
  7. #ifndef _ASM_POWERPC_EXCEPTION_64E_H
  8. #define _ASM_POWERPC_EXCEPTION_64E_H
  9. /*
  10. * SPRGs usage an other considerations...
  11. *
  12. * Since TLB miss and other standard exceptions can be interrupted by
  13. * critical exceptions which can themselves be interrupted by machine
  14. * checks, and since the two later can themselves cause a TLB miss when
  15. * hitting the linear mapping for the kernel stacks, we need to be a bit
  16. * creative on how we use SPRGs.
  17. *
  18. * The base idea is that we have one SRPG reserved for critical and one
  19. * for machine check interrupts. Those are used to save a GPR that can
  20. * then be used to get the PACA, and store as much context as we need
  21. * to save in there. That includes saving the SPRGs used by the TLB miss
  22. * handler for linear mapping misses and the associated SRR0/1 due to
  23. * the above re-entrancy issue.
  24. *
  25. * So here's the current usage pattern. It's done regardless of which
  26. * SPRGs are user-readable though, thus we might have to change some of
  27. * this later. In order to do that more easily, we use special constants
  28. * for naming them
  29. *
  30. * WARNING: Some of these SPRGs are user readable. We need to do something
  31. * about it as some point by making sure they can't be used to leak kernel
  32. * critical data
  33. */
  34. #define PACA_EXGDBELL PACA_EXGEN
  35. /* We are out of SPRGs so we save some things in the PACA. The normal
  36. * exception frame is smaller than the CRIT or MC one though
  37. */
  38. #define EX_R1 (0 * 8)
  39. #define EX_CR (1 * 8)
  40. #define EX_R10 (2 * 8)
  41. #define EX_R11 (3 * 8)
  42. #define EX_R14 (4 * 8)
  43. #define EX_R15 (5 * 8)
  44. /*
  45. * The TLB miss exception uses different slots.
  46. *
  47. * The bolted variant uses only the first six fields,
  48. * which in combination with pgd and kernel_pgd fits in
  49. * one 64-byte cache line.
  50. */
  51. #define EX_TLB_R10 ( 0 * 8)
  52. #define EX_TLB_R11 ( 1 * 8)
  53. #define EX_TLB_R14 ( 2 * 8)
  54. #define EX_TLB_R15 ( 3 * 8)
  55. #define EX_TLB_R16 ( 4 * 8)
  56. #define EX_TLB_CR ( 5 * 8)
  57. #define EX_TLB_R12 ( 6 * 8)
  58. #define EX_TLB_R13 ( 7 * 8)
  59. #define EX_TLB_DEAR ( 8 * 8) /* Level 0 and 2 only */
  60. #define EX_TLB_ESR ( 9 * 8) /* Level 0 and 2 only */
  61. #define EX_TLB_SRR0 (10 * 8)
  62. #define EX_TLB_SRR1 (11 * 8)
  63. #define EX_TLB_R7 (12 * 8)
  64. #define EX_TLB_SIZE (13 * 8)
  65. #define START_EXCEPTION(label) \
  66. .globl exc_##label##_book3e; \
  67. exc_##label##_book3e:
  68. /* TLB miss exception prolog
  69. *
  70. * This prolog handles re-entrancy (up to 3 levels supported in the PACA
  71. * though we currently don't test for overflow). It provides you with a
  72. * re-entrancy safe working space of r10...r16 and CR with r12 being used
  73. * as the exception area pointer in the PACA for that level of re-entrancy
  74. * and r13 containing the PACA pointer.
  75. *
  76. * SRR0 and SRR1 are saved, but DEAR and ESR are not, since they don't apply
  77. * as-is for instruction exceptions. It's up to the actual exception code
  78. * to save them as well if required.
  79. */
  80. #define TLB_MISS_PROLOG \
  81. mtspr SPRN_SPRG_TLB_SCRATCH,r12; \
  82. mfspr r12,SPRN_SPRG_TLB_EXFRAME; \
  83. std r10,EX_TLB_R10(r12); \
  84. mfcr r10; \
  85. std r11,EX_TLB_R11(r12); \
  86. mfspr r11,SPRN_SPRG_TLB_SCRATCH; \
  87. std r13,EX_TLB_R13(r12); \
  88. mfspr r13,SPRN_SPRG_PACA; \
  89. std r14,EX_TLB_R14(r12); \
  90. addi r14,r12,EX_TLB_SIZE; \
  91. std r15,EX_TLB_R15(r12); \
  92. mfspr r15,SPRN_SRR1; \
  93. std r16,EX_TLB_R16(r12); \
  94. mfspr r16,SPRN_SRR0; \
  95. std r10,EX_TLB_CR(r12); \
  96. std r11,EX_TLB_R12(r12); \
  97. mtspr SPRN_SPRG_TLB_EXFRAME,r14; \
  98. std r15,EX_TLB_SRR1(r12); \
  99. std r16,EX_TLB_SRR0(r12);
  100. /* And these are the matching epilogs that restores things
  101. *
  102. * There are 3 epilogs:
  103. *
  104. * - SUCCESS : Unwinds one level
  105. * - ERROR : restore from level 0 and reset
  106. * - ERROR_SPECIAL : restore from current level and reset
  107. *
  108. * Normal errors use ERROR, that is, they restore the initial fault context
  109. * and trigger a fault. However, there is a special case for linear mapping
  110. * errors. Those should basically never happen, but if they do happen, we
  111. * want the error to point out the context that did that linear mapping
  112. * fault, not the initial level 0 (basically, we got a bogus PGF or something
  113. * like that). For userland errors on the linear mapping, there is no
  114. * difference since those are always level 0 anyway
  115. */
  116. #define TLB_MISS_RESTORE(freg) \
  117. ld r14,EX_TLB_CR(r12); \
  118. ld r10,EX_TLB_R10(r12); \
  119. ld r15,EX_TLB_SRR0(r12); \
  120. ld r16,EX_TLB_SRR1(r12); \
  121. mtspr SPRN_SPRG_TLB_EXFRAME,freg; \
  122. ld r11,EX_TLB_R11(r12); \
  123. mtcr r14; \
  124. ld r13,EX_TLB_R13(r12); \
  125. ld r14,EX_TLB_R14(r12); \
  126. mtspr SPRN_SRR0,r15; \
  127. ld r15,EX_TLB_R15(r12); \
  128. mtspr SPRN_SRR1,r16; \
  129. ld r16,EX_TLB_R16(r12); \
  130. ld r12,EX_TLB_R12(r12); \
  131. #define TLB_MISS_EPILOG_SUCCESS \
  132. TLB_MISS_RESTORE(r12)
  133. #define TLB_MISS_EPILOG_ERROR \
  134. addi r12,r13,PACA_EXTLB; \
  135. TLB_MISS_RESTORE(r12)
  136. #define TLB_MISS_EPILOG_ERROR_SPECIAL \
  137. addi r11,r13,PACA_EXTLB; \
  138. TLB_MISS_RESTORE(r11)
  139. #ifndef __ASSEMBLY__
  140. extern unsigned int interrupt_base_book3e;
  141. #endif
  142. #define SET_IVOR(vector_number, vector_offset) \
  143. LOAD_REG_ADDR(r3,interrupt_base_book3e);\
  144. ori r3,r3,vector_offset@l; \
  145. mtspr SPRN_IVOR##vector_number,r3;
  146. /*
  147. * powerpc relies on return from interrupt/syscall being context synchronising
  148. * (which rfi is) to support ARCH_HAS_MEMBARRIER_SYNC_CORE without additional
  149. * synchronisation instructions.
  150. */
  151. #define RFI_TO_KERNEL \
  152. rfi
  153. #define RFI_TO_USER \
  154. rfi
  155. #endif /* _ASM_POWERPC_EXCEPTION_64E_H */