trap_block.h 6.4 KB

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