ktlb.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
  2. *
  3. * Copyright (C) 1995, 1997, 2005 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 <linux/config.h>
  9. #include <asm/head.h>
  10. #include <asm/asi.h>
  11. #include <asm/page.h>
  12. #include <asm/pgtable.h>
  13. #include <asm/tsb.h>
  14. .text
  15. .align 32
  16. kvmap_itlb:
  17. /* g6: TAG TARGET */
  18. mov TLB_TAG_ACCESS, %g4
  19. ldxa [%g4] ASI_IMMU, %g4
  20. /* sun4v_itlb_miss branches here with the missing virtual
  21. * address already loaded into %g4
  22. */
  23. kvmap_itlb_4v:
  24. kvmap_itlb_nonlinear:
  25. /* Catch kernel NULL pointer calls. */
  26. sethi %hi(PAGE_SIZE), %g5
  27. cmp %g4, %g5
  28. bleu,pn %xcc, kvmap_dtlb_longpath
  29. nop
  30. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
  31. kvmap_itlb_tsb_miss:
  32. sethi %hi(LOW_OBP_ADDRESS), %g5
  33. cmp %g4, %g5
  34. blu,pn %xcc, kvmap_itlb_vmalloc_addr
  35. mov 0x1, %g5
  36. sllx %g5, 32, %g5
  37. cmp %g4, %g5
  38. blu,pn %xcc, kvmap_itlb_obp
  39. nop
  40. kvmap_itlb_vmalloc_addr:
  41. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
  42. KTSB_LOCK_TAG(%g1, %g2, %g7)
  43. /* Load and check PTE. */
  44. ldxa [%g5] ASI_PHYS_USE_EC, %g5
  45. mov 1, %g7
  46. sllx %g7, TSB_TAG_INVALID_BIT, %g7
  47. brgez,a,pn %g5, kvmap_itlb_longpath
  48. KTSB_STORE(%g1, %g7)
  49. KTSB_WRITE(%g1, %g5, %g6)
  50. /* fallthrough to TLB load */
  51. kvmap_itlb_load:
  52. 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
  53. retry
  54. .section .sun4v_2insn_patch, "ax"
  55. .word 661b
  56. nop
  57. nop
  58. .previous
  59. /* For sun4v the ASI_ITLB_DATA_IN store and the retry
  60. * instruction get nop'd out and we get here to branch
  61. * to the sun4v tlb load code. The registers are setup
  62. * as follows:
  63. *
  64. * %g4: vaddr
  65. * %g5: PTE
  66. * %g6: TAG
  67. *
  68. * The sun4v TLB load wants the PTE in %g3 so we fix that
  69. * up here.
  70. */
  71. ba,pt %xcc, sun4v_itlb_load
  72. mov %g5, %g3
  73. kvmap_itlb_longpath:
  74. 661: rdpr %pstate, %g5
  75. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  76. .section .sun4v_2insn_patch, "ax"
  77. .word 661b
  78. SET_GL(1)
  79. nop
  80. .previous
  81. rdpr %tpc, %g5
  82. ba,pt %xcc, sparc64_realfault_common
  83. mov FAULT_CODE_ITLB, %g4
  84. kvmap_itlb_obp:
  85. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
  86. KTSB_LOCK_TAG(%g1, %g2, %g7)
  87. KTSB_WRITE(%g1, %g5, %g6)
  88. ba,pt %xcc, kvmap_itlb_load
  89. nop
  90. kvmap_dtlb_obp:
  91. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
  92. KTSB_LOCK_TAG(%g1, %g2, %g7)
  93. KTSB_WRITE(%g1, %g5, %g6)
  94. ba,pt %xcc, kvmap_dtlb_load
  95. nop
  96. .align 32
  97. kvmap_dtlb_tsb4m_load:
  98. KTSB_LOCK_TAG(%g1, %g2, %g7)
  99. KTSB_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. /* sun4v_dtlb_miss branches here with the missing virtual
  107. * address already loaded into %g4
  108. */
  109. kvmap_dtlb_4v:
  110. brgez,pn %g4, kvmap_dtlb_nonlinear
  111. nop
  112. /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
  113. KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  114. /* TSB entry address left in %g1, lookup linear PTE.
  115. * Must preserve %g1 and %g6 (TAG).
  116. */
  117. kvmap_dtlb_tsb4m_miss:
  118. sethi %hi(kpte_linear_bitmap), %g2
  119. or %g2, %lo(kpte_linear_bitmap), %g2
  120. /* Clear the PAGE_OFFSET top virtual bits, then shift
  121. * down to get a 256MB physical address index.
  122. */
  123. sllx %g4, 21, %g5
  124. mov 1, %g7
  125. srlx %g5, 21 + 28, %g5
  126. /* Don't try this at home kids... this depends upon srlx
  127. * only taking the low 6 bits of the shift count in %g5.
  128. */
  129. sllx %g7, %g5, %g7
  130. /* Divide by 64 to get the offset into the bitmask. */
  131. srlx %g5, 6, %g5
  132. sllx %g5, 3, %g5
  133. /* kern_linear_pte_xor[((mask & bit) ? 1 : 0)] */
  134. ldx [%g2 + %g5], %g2
  135. andcc %g2, %g7, %g0
  136. sethi %hi(kern_linear_pte_xor), %g5
  137. or %g5, %lo(kern_linear_pte_xor), %g5
  138. bne,a,pt %xcc, 1f
  139. add %g5, 8, %g5
  140. 1: ldx [%g5], %g2
  141. .globl kvmap_linear_patch
  142. kvmap_linear_patch:
  143. ba,pt %xcc, kvmap_dtlb_tsb4m_load
  144. xor %g2, %g4, %g5
  145. kvmap_dtlb_vmalloc_addr:
  146. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
  147. KTSB_LOCK_TAG(%g1, %g2, %g7)
  148. /* Load and check PTE. */
  149. ldxa [%g5] ASI_PHYS_USE_EC, %g5
  150. mov 1, %g7
  151. sllx %g7, TSB_TAG_INVALID_BIT, %g7
  152. brgez,a,pn %g5, kvmap_dtlb_longpath
  153. KTSB_STORE(%g1, %g7)
  154. KTSB_WRITE(%g1, %g5, %g6)
  155. /* fallthrough to TLB load */
  156. kvmap_dtlb_load:
  157. 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
  158. retry
  159. .section .sun4v_2insn_patch, "ax"
  160. .word 661b
  161. nop
  162. nop
  163. .previous
  164. /* For sun4v the ASI_DTLB_DATA_IN store and the retry
  165. * instruction get nop'd out and we get here to branch
  166. * to the sun4v tlb load code. The registers are setup
  167. * as follows:
  168. *
  169. * %g4: vaddr
  170. * %g5: PTE
  171. * %g6: TAG
  172. *
  173. * The sun4v TLB load wants the PTE in %g3 so we fix that
  174. * up here.
  175. */
  176. ba,pt %xcc, sun4v_dtlb_load
  177. mov %g5, %g3
  178. kvmap_dtlb_nonlinear:
  179. /* Catch kernel NULL pointer derefs. */
  180. sethi %hi(PAGE_SIZE), %g5
  181. cmp %g4, %g5
  182. bleu,pn %xcc, kvmap_dtlb_longpath
  183. nop
  184. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  185. kvmap_dtlb_tsbmiss:
  186. sethi %hi(MODULES_VADDR), %g5
  187. cmp %g4, %g5
  188. blu,pn %xcc, kvmap_dtlb_longpath
  189. mov (VMALLOC_END >> 24), %g5
  190. sllx %g5, 24, %g5
  191. cmp %g4, %g5
  192. bgeu,pn %xcc, kvmap_dtlb_longpath
  193. nop
  194. kvmap_check_obp:
  195. sethi %hi(LOW_OBP_ADDRESS), %g5
  196. cmp %g4, %g5
  197. blu,pn %xcc, kvmap_dtlb_vmalloc_addr
  198. mov 0x1, %g5
  199. sllx %g5, 32, %g5
  200. cmp %g4, %g5
  201. blu,pn %xcc, kvmap_dtlb_obp
  202. nop
  203. ba,pt %xcc, kvmap_dtlb_vmalloc_addr
  204. nop
  205. kvmap_dtlb_longpath:
  206. 661: rdpr %pstate, %g5
  207. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  208. .section .sun4v_2insn_patch, "ax"
  209. .word 661b
  210. SET_GL(1)
  211. ldxa [%g0] ASI_SCRATCHPAD, %g5
  212. .previous
  213. rdpr %tl, %g3
  214. cmp %g3, 1
  215. 661: mov TLB_TAG_ACCESS, %g4
  216. ldxa [%g4] ASI_DMMU, %g5
  217. .section .sun4v_2insn_patch, "ax"
  218. .word 661b
  219. ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
  220. nop
  221. .previous
  222. be,pt %xcc, sparc64_realfault_common
  223. mov FAULT_CODE_DTLB, %g4
  224. ba,pt %xcc, winfix_trampoline
  225. nop