trap_block.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. extern void init_cur_cpu_trap(struct thread_info *);
  47. extern void setup_tba(void);
  48. extern int ncpus_probed;
  49. extern unsigned long real_hard_smp_processor_id(void);
  50. struct cpuid_patch_entry {
  51. unsigned int addr;
  52. unsigned int cheetah_safari[4];
  53. unsigned int cheetah_jbus[4];
  54. unsigned int starfire[4];
  55. unsigned int sun4v[4];
  56. };
  57. extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
  58. struct sun4v_1insn_patch_entry {
  59. unsigned int addr;
  60. unsigned int insn;
  61. };
  62. extern struct sun4v_1insn_patch_entry __sun4v_1insn_patch,
  63. __sun4v_1insn_patch_end;
  64. struct sun4v_2insn_patch_entry {
  65. unsigned int addr;
  66. unsigned int insns[2];
  67. };
  68. extern struct sun4v_2insn_patch_entry __sun4v_2insn_patch,
  69. __sun4v_2insn_patch_end;
  70. #endif /* !(__ASSEMBLY__) */
  71. #define TRAP_PER_CPU_THREAD 0x00
  72. #define TRAP_PER_CPU_PGD_PADDR 0x08
  73. #define TRAP_PER_CPU_CPU_MONDO_PA 0x10
  74. #define TRAP_PER_CPU_DEV_MONDO_PA 0x18
  75. #define TRAP_PER_CPU_RESUM_MONDO_PA 0x20
  76. #define TRAP_PER_CPU_RESUM_KBUF_PA 0x28
  77. #define TRAP_PER_CPU_NONRESUM_MONDO_PA 0x30
  78. #define TRAP_PER_CPU_NONRESUM_KBUF_PA 0x38
  79. #define TRAP_PER_CPU_FAULT_INFO 0x40
  80. #define TRAP_PER_CPU_CPU_MONDO_BLOCK_PA 0xc0
  81. #define TRAP_PER_CPU_CPU_LIST_PA 0xc8
  82. #define TRAP_PER_CPU_TSB_HUGE 0xd0
  83. #define TRAP_PER_CPU_TSB_HUGE_TEMP 0xd8
  84. #define TRAP_PER_CPU_IRQ_WORKLIST_PA 0xe0
  85. #define TRAP_PER_CPU_CPU_MONDO_QMASK 0xe8
  86. #define TRAP_PER_CPU_DEV_MONDO_QMASK 0xec
  87. #define TRAP_PER_CPU_RESUM_QMASK 0xf0
  88. #define TRAP_PER_CPU_NONRESUM_QMASK 0xf4
  89. #define TRAP_PER_CPU_PER_CPU_BASE 0xf8
  90. #define TRAP_BLOCK_SZ_SHIFT 8
  91. #include <asm/scratchpad.h>
  92. #define __GET_CPUID(REG) \
  93. /* Spitfire implementation (default). */ \
  94. 661: ldxa [%g0] ASI_UPA_CONFIG, REG; \
  95. srlx REG, 17, REG; \
  96. and REG, 0x1f, REG; \
  97. nop; \
  98. .section .cpuid_patch, "ax"; \
  99. /* Instruction location. */ \
  100. .word 661b; \
  101. /* Cheetah Safari implementation. */ \
  102. ldxa [%g0] ASI_SAFARI_CONFIG, REG; \
  103. srlx REG, 17, REG; \
  104. and REG, 0x3ff, REG; \
  105. nop; \
  106. /* Cheetah JBUS implementation. */ \
  107. ldxa [%g0] ASI_JBUS_CONFIG, REG; \
  108. srlx REG, 17, REG; \
  109. and REG, 0x1f, REG; \
  110. nop; \
  111. /* Starfire implementation. */ \
  112. sethi %hi(0x1fff40000d0 >> 9), REG; \
  113. sllx REG, 9, REG; \
  114. or REG, 0xd0, REG; \
  115. lduwa [REG] ASI_PHYS_BYPASS_EC_E, REG;\
  116. /* sun4v implementation. */ \
  117. mov SCRATCHPAD_CPUID, REG; \
  118. ldxa [REG] ASI_SCRATCHPAD, REG; \
  119. nop; \
  120. nop; \
  121. .previous;
  122. #ifdef CONFIG_SMP
  123. #define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  124. __GET_CPUID(TMP) \
  125. sethi %hi(trap_block), DEST; \
  126. sllx TMP, TRAP_BLOCK_SZ_SHIFT, TMP; \
  127. or DEST, %lo(trap_block), DEST; \
  128. add DEST, TMP, DEST; \
  129. /* Clobbers TMP, current address space PGD phys address into DEST. */
  130. #define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
  131. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  132. ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
  133. /* Clobbers TMP, loads local processor's IRQ work area into DEST. */
  134. #define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
  135. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  136. add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
  137. /* Clobbers TMP, loads DEST with current thread info pointer. */
  138. #define TRAP_LOAD_THREAD_REG(DEST, TMP) \
  139. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  140. ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
  141. /* Given the current thread info pointer in THR, load the per-cpu
  142. * area base of the current processor into DEST. REG1, REG2, and REG3 are
  143. * clobbered.
  144. *
  145. * You absolutely cannot use DEST as a temporary in this code. The
  146. * reason is that traps can happen during execution, and return from
  147. * trap will load the fully resolved DEST per-cpu base. This can corrupt
  148. * the calculations done by the macro mid-stream.
  149. */
  150. #define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3) \
  151. lduh [THR + TI_CPU], REG1; \
  152. sethi %hi(trap_block), REG2; \
  153. sllx REG1, TRAP_BLOCK_SZ_SHIFT, REG1; \
  154. or REG2, %lo(trap_block), REG2; \
  155. add REG2, REG1, REG2; \
  156. ldx [REG2 + TRAP_PER_CPU_PER_CPU_BASE], DEST;
  157. #else
  158. #define TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  159. sethi %hi(trap_block), DEST; \
  160. or DEST, %lo(trap_block), DEST; \
  161. /* Uniprocessor versions, we know the cpuid is zero. */
  162. #define TRAP_LOAD_PGD_PHYS(DEST, TMP) \
  163. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  164. ldx [DEST + TRAP_PER_CPU_PGD_PADDR], DEST;
  165. /* Clobbers TMP, loads local processor's IRQ work area into DEST. */
  166. #define TRAP_LOAD_IRQ_WORK_PA(DEST, TMP) \
  167. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  168. add DEST, TRAP_PER_CPU_IRQ_WORKLIST_PA, DEST;
  169. #define TRAP_LOAD_THREAD_REG(DEST, TMP) \
  170. TRAP_LOAD_TRAP_BLOCK(DEST, TMP) \
  171. ldx [DEST + TRAP_PER_CPU_THREAD], DEST;
  172. /* No per-cpu areas on uniprocessor, so no need to load DEST. */
  173. #define LOAD_PER_CPU_BASE(DEST, THR, REG1, REG2, REG3)
  174. #endif /* !(CONFIG_SMP) */
  175. #endif /* _SPARC_TRAP_BLOCK_H */