ktlb.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
  2. *
  3. * Copyright (C) 1995, 1997, 2005, 2008 David S. Miller <davem@davemloft.net>
  4. * Copyright (C) 1996 Eddie C. Dost (ecd@brainaid.de)
  5. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. */
  8. #include <asm/head.h>
  9. #include <asm/asi.h>
  10. #include <asm/page.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/tsb.h>
  13. .text
  14. .align 32
  15. kvmap_itlb:
  16. /* g6: TAG TARGET */
  17. mov TLB_TAG_ACCESS, %g4
  18. ldxa [%g4] ASI_IMMU, %g4
  19. /* The kernel executes in context zero, therefore we do not
  20. * need to clear the context ID bits out of %g4 here.
  21. */
  22. /* sun4v_itlb_miss branches here with the missing virtual
  23. * address already loaded into %g4
  24. */
  25. kvmap_itlb_4v:
  26. /* Catch kernel NULL pointer calls. */
  27. sethi %hi(PAGE_SIZE), %g5
  28. cmp %g4, %g5
  29. blu,pn %xcc, kvmap_itlb_longpath
  30. nop
  31. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
  32. kvmap_itlb_tsb_miss:
  33. sethi %hi(LOW_OBP_ADDRESS), %g5
  34. cmp %g4, %g5
  35. blu,pn %xcc, kvmap_itlb_vmalloc_addr
  36. mov 0x1, %g5
  37. sllx %g5, 32, %g5
  38. cmp %g4, %g5
  39. blu,pn %xcc, kvmap_itlb_obp
  40. nop
  41. kvmap_itlb_vmalloc_addr:
  42. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
  43. TSB_LOCK_TAG(%g1, %g2, %g7)
  44. TSB_WRITE(%g1, %g5, %g6)
  45. /* fallthrough to TLB load */
  46. kvmap_itlb_load:
  47. 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
  48. retry
  49. .section .sun4v_2insn_patch, "ax"
  50. .word 661b
  51. nop
  52. nop
  53. .previous
  54. /* For sun4v the ASI_ITLB_DATA_IN store and the retry
  55. * instruction get nop'd out and we get here to branch
  56. * to the sun4v tlb load code. The registers are setup
  57. * as follows:
  58. *
  59. * %g4: vaddr
  60. * %g5: PTE
  61. * %g6: TAG
  62. *
  63. * The sun4v TLB load wants the PTE in %g3 so we fix that
  64. * up here.
  65. */
  66. ba,pt %xcc, sun4v_itlb_load
  67. mov %g5, %g3
  68. kvmap_itlb_longpath:
  69. 661: rdpr %pstate, %g5
  70. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  71. .section .sun4v_2insn_patch, "ax"
  72. .word 661b
  73. SET_GL(1)
  74. nop
  75. .previous
  76. rdpr %tpc, %g5
  77. ba,pt %xcc, sparc64_realfault_common
  78. mov FAULT_CODE_ITLB, %g4
  79. kvmap_itlb_obp:
  80. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
  81. TSB_LOCK_TAG(%g1, %g2, %g7)
  82. TSB_WRITE(%g1, %g5, %g6)
  83. ba,pt %xcc, kvmap_itlb_load
  84. nop
  85. kvmap_dtlb_obp:
  86. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
  87. TSB_LOCK_TAG(%g1, %g2, %g7)
  88. TSB_WRITE(%g1, %g5, %g6)
  89. ba,pt %xcc, kvmap_dtlb_load
  90. nop
  91. kvmap_linear_early:
  92. sethi %hi(kern_linear_pte_xor), %g7
  93. ldx [%g7 + %lo(kern_linear_pte_xor)], %g2
  94. ba,pt %xcc, kvmap_dtlb_tsb4m_load
  95. xor %g2, %g4, %g5
  96. .align 32
  97. kvmap_dtlb_tsb4m_load:
  98. TSB_LOCK_TAG(%g1, %g2, %g7)
  99. TSB_WRITE(%g1, %g5, %g6)
  100. ba,pt %xcc, kvmap_dtlb_load
  101. nop
  102. kvmap_dtlb:
  103. /* %g6: TAG TARGET */
  104. mov TLB_TAG_ACCESS, %g4
  105. ldxa [%g4] ASI_DMMU, %g4
  106. /* The kernel executes in context zero, therefore we do not
  107. * need to clear the context ID bits out of %g4 here.
  108. */
  109. /* sun4v_dtlb_miss branches here with the missing virtual
  110. * address already loaded into %g4
  111. */
  112. kvmap_dtlb_4v:
  113. brgez,pn %g4, kvmap_dtlb_nonlinear
  114. nop
  115. #ifdef CONFIG_DEBUG_PAGEALLOC
  116. /* Index through the base page size TSB even for linear
  117. * mappings when using page allocation debugging.
  118. */
  119. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  120. #else
  121. /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
  122. KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  123. #endif
  124. /* Linear mapping TSB lookup failed. Fallthrough to kernel
  125. * page table based lookup.
  126. */
  127. .globl kvmap_linear_patch
  128. kvmap_linear_patch:
  129. ba,a,pt %xcc, kvmap_linear_early
  130. kvmap_dtlb_vmalloc_addr:
  131. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
  132. TSB_LOCK_TAG(%g1, %g2, %g7)
  133. TSB_WRITE(%g1, %g5, %g6)
  134. /* fallthrough to TLB load */
  135. kvmap_dtlb_load:
  136. 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
  137. retry
  138. .section .sun4v_2insn_patch, "ax"
  139. .word 661b
  140. nop
  141. nop
  142. .previous
  143. /* For sun4v the ASI_DTLB_DATA_IN store and the retry
  144. * instruction get nop'd out and we get here to branch
  145. * to the sun4v tlb load code. The registers are setup
  146. * as follows:
  147. *
  148. * %g4: vaddr
  149. * %g5: PTE
  150. * %g6: TAG
  151. *
  152. * The sun4v TLB load wants the PTE in %g3 so we fix that
  153. * up here.
  154. */
  155. ba,pt %xcc, sun4v_dtlb_load
  156. mov %g5, %g3
  157. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  158. kvmap_vmemmap:
  159. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
  160. ba,a,pt %xcc, kvmap_dtlb_load
  161. #endif
  162. kvmap_dtlb_nonlinear:
  163. /* Catch kernel NULL pointer derefs. */
  164. sethi %hi(PAGE_SIZE), %g5
  165. cmp %g4, %g5
  166. bleu,pn %xcc, kvmap_dtlb_longpath
  167. nop
  168. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  169. /* Do not use the TSB for vmemmap. */
  170. sethi %hi(VMEMMAP_BASE), %g5
  171. ldx [%g5 + %lo(VMEMMAP_BASE)], %g5
  172. cmp %g4,%g5
  173. bgeu,pn %xcc, kvmap_vmemmap
  174. nop
  175. #endif
  176. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  177. kvmap_dtlb_tsbmiss:
  178. sethi %hi(MODULES_VADDR), %g5
  179. cmp %g4, %g5
  180. blu,pn %xcc, kvmap_dtlb_longpath
  181. sethi %hi(VMALLOC_END), %g5
  182. ldx [%g5 + %lo(VMALLOC_END)], %g5
  183. cmp %g4, %g5
  184. bgeu,pn %xcc, kvmap_dtlb_longpath
  185. nop
  186. kvmap_check_obp:
  187. sethi %hi(LOW_OBP_ADDRESS), %g5
  188. cmp %g4, %g5
  189. blu,pn %xcc, kvmap_dtlb_vmalloc_addr
  190. mov 0x1, %g5
  191. sllx %g5, 32, %g5
  192. cmp %g4, %g5
  193. blu,pn %xcc, kvmap_dtlb_obp
  194. nop
  195. ba,pt %xcc, kvmap_dtlb_vmalloc_addr
  196. nop
  197. kvmap_dtlb_longpath:
  198. 661: rdpr %pstate, %g5
  199. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  200. .section .sun4v_2insn_patch, "ax"
  201. .word 661b
  202. SET_GL(1)
  203. ldxa [%g0] ASI_SCRATCHPAD, %g5
  204. .previous
  205. rdpr %tl, %g3
  206. cmp %g3, 1
  207. 661: mov TLB_TAG_ACCESS, %g4
  208. ldxa [%g4] ASI_DMMU, %g5
  209. .section .sun4v_2insn_patch, "ax"
  210. .word 661b
  211. ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
  212. nop
  213. .previous
  214. /* The kernel executes in context zero, therefore we do not
  215. * need to clear the context ID bits out of %g5 here.
  216. */
  217. be,pt %xcc, sparc64_realfault_common
  218. mov FAULT_CODE_DTLB, %g4
  219. ba,pt %xcc, winfix_trampoline
  220. nop