trap_block.h 6.6 KB

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