trap_block.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SPARC_TRAP_BLOCK_H
  3. #define _SPARC_TRAP_BLOCK_H
  4. #include <asm/hypervisor.h>
  5. #include <asm/asi.h>
  6. #ifndef __ASSEMBLY__
  7. /* Trap handling code needs to get at a few critical values upon
  8. * trap entry and to process TSB misses. These cannot be in the
  9. * per_cpu() area as we really need to lock them into the TLB and
  10. * thus make them part of the main kernel image. As a result we
  11. * try to make this as small as possible.
  12. *
  13. * This is padded out and aligned to 64-bytes to avoid false sharing
  14. * on SMP.
  15. */
  16. /* If you modify the size of this structure, please update
  17. * TRAP_BLOCK_SZ_SHIFT below.
  18. */
  19. struct thread_info;
  20. struct trap_per_cpu {
  21. /* D-cache line 1: Basic thread information, cpu and device mondo queues */
  22. struct thread_info *thread;
  23. unsigned long pgd_paddr;
  24. unsigned long cpu_mondo_pa;
  25. unsigned long dev_mondo_pa;
  26. /* D-cache line 2: Error Mondo Queue and kernel buffer pointers */
  27. unsigned long resum_mondo_pa;
  28. unsigned long resum_kernel_buf_pa;
  29. unsigned long nonresum_mondo_pa;
  30. unsigned long nonresum_kernel_buf_pa;
  31. /* Dcache lines 3, 4, 5, and 6: Hypervisor Fault Status */
  32. struct hv_fault_status fault_info;
  33. /* Dcache line 7: Physical addresses of CPU send mondo block and CPU list. */
  34. unsigned long cpu_mondo_block_pa;
  35. unsigned long cpu_list_pa;
  36. unsigned long tsb_huge;
  37. unsigned long tsb_huge_temp;
  38. /* Dcache line 8: IRQ work list, and keep trap_block a power-of-2 in size. */
  39. unsigned long irq_worklist_pa;
  40. unsigned int cpu_mondo_qmask;
  41. unsigned int dev_mondo_qmask;
  42. unsigned int resum_qmask;
  43. unsigned int nonresum_qmask;
  44. unsigned long __per_cpu_base;
  45. } __attribute__((aligned(64)));
  46. extern struct trap_per_cpu trap_block[NR_CPUS];
  47. void init_cur_cpu_trap(struct thread_info *);
  48. void setup_tba(void);
  49. extern int ncpus_probed;
  50. extern u64 cpu_mondo_counter[NR_CPUS];
  51. unsigned long real_hard_smp_processor_id(void);
  52. struct cpuid_patch_entry {
  53. unsigned int addr;
  54. unsigned int cheetah_safari[4];
  55. unsigned int cheetah_jbus[4];
  56. unsigned int starfire[4];
  57. unsigned int sun4v[4];
  58. };
  59. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  60. struct sun4v_1insn_patch_entry {
  61. unsigned int addr;
  62. unsigned int insn;
  63. };
  64. extern struct sun4v_1insn_patch_entry __sun4v_1insn_patch,
  65. __sun4v_1insn_patch_end;
  66. extern struct sun4v_1insn_patch_entry __fast_win_ctrl_1insn_patch,
  67. __fast_win_ctrl_1insn_patch_end;
  68. extern struct sun4v_1insn_patch_entry __sun_m7_1insn_patch,
  69. __sun_m7_1insn_patch_end;
  70. struct sun4v_2insn_patch_entry {
  71. unsigned int addr;
  72. unsigned int insns[2];
  73. };
  74. extern struct sun4v_2insn_patch_entry __sun4v_2insn_patch,
  75. __sun4v_2insn_patch_end;
  76. extern struct sun4v_2insn_patch_entry __sun_m7_2insn_patch,
  77. __sun_m7_2insn_patch_end;
  78. #endif /* !(__ASSEMBLY__) */
  79. #define TRAP_PER_CPU_THREAD 0x00
  80. #define TRAP_PER_CPU_PGD_PADDR 0x08
  81. #define TRAP_PER_CPU_CPU_MONDO_PA 0x10
  82. #define TRAP_PER_CPU_DEV_MONDO_PA 0x18
  83. #define TRAP_PER_CPU_RESUM_MONDO_PA 0x20
  84. #define TRAP_PER_CPU_RESUM_KBUF_PA 0x28
  85. #define TRAP_PER_CPU_NONRESUM_MONDO_PA 0x30
  86. #define TRAP_PER_CPU_NONRESUM_KBUF_PA 0x38
  87. #define TRAP_PER_CPU_FAULT_INFO 0x40
  88. #define TRAP_PER_CPU_CPU_MONDO_BLOCK_PA 0xc0
  89. #define TRAP_PER_CPU_CPU_LIST_PA 0xc8
  90. #define TRAP_PER_CPU_TSB_HUGE 0xd0
  91. #define TRAP_PER_CPU_TSB_HUGE_TEMP 0xd8
  92. #define TRAP_PER_CPU_IRQ_WORKLIST_PA 0xe0
  93. #define TRAP_PER_CPU_CPU_MONDO_QMASK 0xe8
  94. #define TRAP_PER_CPU_DEV_MONDO_QMASK 0xec
  95. #define TRAP_PER_CPU_RESUM_QMASK 0xf0
  96. #define TRAP_PER_CPU_NONRESUM_QMASK 0xf4
  97. #define TRAP_PER_CPU_PER_CPU_BASE 0xf8
  98. #define TRAP_BLOCK_SZ_SHIFT 8
  99. #include <asm/scratchpad.h>
  100. #define __GET_CPUID(REG) \
  101. /* Spitfire implementation (default). */ \
  102. 661: ldxa [%g0] ASI_UPA_CONFIG, REG; \
  103. srlx REG, 17, REG; \
  104. and REG, 0x1f, REG; \
  105. nop; \
  106. .section .cpuid_patch, "ax"; \
  107. /* Instruction location. */ \
  108. .word 661b; \
  109. /* Cheetah Safari implementation. */ \
  110. ldxa [%g0] ASI_SAFARI_CONFIG, REG; \
  111. srlx REG, 17, REG; \
  112. and REG, 0x3ff, REG; \
  113. nop; \
  114. /* Cheetah JBUS implementation. */ \
  115. ldxa [%g0] ASI_JBUS_CONFIG, REG; \
  116. srlx REG, 17, REG; \
  117. and REG, 0x1f, REG; \
  118. nop; \
  119. /* Starfire implementation. */ \
  120. sethi %hi(0x1fff40000d0 >> 9), REG; \
  121. sllx REG, 9, REG; \
  122. or REG, 0xd0, REG; \
  123. lduwa [REG] ASI_PHYS_BYPASS_EC_E, REG;\
  124. /* sun4v implementation. */ \
  125. mov SCRATCHPAD_CPUID, REG; \
  126. ldxa [REG] ASI_SCRATCHPAD, REG; \
  127. nop; \
  128. nop; \
  129. .previous;
  130. #ifdef CONFIG_SMP
  131. #define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  132. __GET_CPUID(TMP) \
  133. sethi %hi(trap_block), DEST; \
  134. sllx TMP, TRAP_BLOCK_SZ_SHIFT, TMP; \
  135. or DEST, %lo(trap_block), DEST; \
  136. add DEST, TMP, DEST; \
  137. /* Clobbers TMP, current address space PGD phys address into DEST. */
  138. #define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
  139. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  140. ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
  141. /* Clobbers TMP, loads local processor's IRQ work area into DEST. */
  142. #define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
  143. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  144. add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
  145. /* Clobbers TMP, loads DEST with current thread info pointer. */
  146. #define TRAP_LOAD_THREAD_REG(DEST, TMP) \
  147. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  148. ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
  149. /* Given the current thread info pointer in THR, load the per-cpu
  150. * area base of the current processor into DEST. REG1, REG2, and REG3 are
  151. * clobbered.
  152. *
  153. * You absolutely cannot use DEST as a temporary in this code. The
  154. * reason is that traps can happen during execution, and return from
  155. * trap will load the fully resolved DEST per-cpu base. This can corrupt
  156. * the calculations done by the macro mid-stream.
  157. */
  158. #define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3) \
  159. lduh [THR + TI_CPU], REG1; \
  160. sethi %hi(trap_block), REG2; \
  161. sllx REG1, TRAP_BLOCK_SZ_SHIFT, REG1; \
  162. or REG2, %lo(trap_block), REG2; \
  163. add REG2, REG1, REG2; \
  164. ldx [REG2 + TRAP_PER_CPU_PER_CPU_BASE], DEST;
  165. #else
  166. #define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  167. sethi %hi(trap_block), DEST; \
  168. or DEST, %lo(trap_block), DEST; \
  169. /* Uniprocessor versions, we know the cpuid is zero. */
  170. #define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
  171. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  172. ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
  173. /* Clobbers TMP, loads local processor's IRQ work area into DEST. */
  174. #define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
  175. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  176. add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
  177. #define TRAP_LOAD_THREAD_REG(DEST, TMP) \
  178. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  179. ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
  180. /* No per-cpu areas on uniprocessor, so no need to load DEST. */
  181. #define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3)
  182. #endif /* !(CONFIG_SMP) */
  183. #endif /* _SPARC_TRAP_BLOCK_H */