tsb.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* tsb.S: Sparc64 TSB table handling.
  2. *
  3. * Copyright (C) 2006 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <asm/tsb.h>
  6. .text
  7. .align 32
  8. /* Invoked from TLB miss handler, we are in the
  9. * MMU global registers and they are setup like
  10. * this:
  11. *
  12. * %g1: TSB entry pointer
  13. * %g2: available temporary
  14. * %g3: FAULT_CODE_{D,I}TLB
  15. * %g4: available temporary
  16. * %g5: available temporary
  17. * %g6: TAG TARGET
  18. * %g7: available temporary, will be loaded by us with
  19. * the physical address base of the linux page
  20. * tables for the current address space
  21. */
  22. tsb_miss_dtlb:
  23. mov TLB_TAG_ACCESS, %g4
  24. ldxa [%g4] ASI_DMMU, %g4
  25. ba,pt %xcc, tsb_miss_page_table_walk
  26. nop
  27. tsb_miss_itlb:
  28. mov TLB_TAG_ACCESS, %g4
  29. ldxa [%g4] ASI_IMMU, %g4
  30. ba,pt %xcc, tsb_miss_page_table_walk
  31. nop
  32. /* The sun4v TLB miss handlers jump directly here instead
  33. * of tsb_miss_{d,i}tlb with registers setup as follows:
  34. *
  35. * %g4: missing virtual address
  36. * %g1: TSB entry address loaded
  37. * %g6: TAG TARGET ((vaddr >> 22) | (ctx << 48))
  38. */
  39. tsb_miss_page_table_walk:
  40. TRAP_LOAD_PGD_PHYS(%g7, %g5)
  41. USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
  42. tsb_reload:
  43. TSB_LOCK_TAG(%g1, %g2, %g7)
  44. /* Load and check PTE. */
  45. ldxa [%g5] ASI_PHYS_USE_EC, %g5
  46. brgez,a,pn %g5, tsb_do_fault
  47. TSB_STORE(%g1, %g0)
  48. /* If it is larger than the base page size, don't
  49. * bother putting it into the TSB.
  50. */
  51. srlx %g5, 32, %g2
  52. sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g7
  53. and %g2, %g7, %g2
  54. sethi %hi(_PAGE_SZBITS >> 32), %g7
  55. cmp %g2, %g7
  56. bne,a,pn %xcc, tsb_tlb_reload
  57. TSB_STORE(%g1, %g0)
  58. TSB_WRITE(%g1, %g5, %g6)
  59. /* Finally, load TLB and return from trap. */
  60. tsb_tlb_reload:
  61. cmp %g3, FAULT_CODE_DTLB
  62. bne,pn %xcc, tsb_itlb_load
  63. nop
  64. tsb_dtlb_load:
  65. 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
  66. retry
  67. .section .sun4v_2insn_patch, "ax"
  68. .word 661b
  69. nop
  70. nop
  71. .previous
  72. /* For sun4v the ASI_DTLB_DATA_IN store and the retry
  73. * instruction get nop'd out and we get here to branch
  74. * to the sun4v tlb load code. The registers are setup
  75. * as follows:
  76. *
  77. * %g4: vaddr
  78. * %g5: PTE
  79. * %g6: TAG
  80. *
  81. * The sun4v TLB load wants the PTE in %g3 so we fix that
  82. * up here.
  83. */
  84. ba,pt %xcc, sun4v_dtlb_load
  85. mov %g5, %g3
  86. tsb_itlb_load:
  87. 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
  88. retry
  89. .section .sun4v_2insn_patch, "ax"
  90. .word 661b
  91. nop
  92. nop
  93. .previous
  94. /* For sun4v the ASI_ITLB_DATA_IN store and the retry
  95. * instruction get nop'd out and we get here to branch
  96. * to the sun4v tlb load code. The registers are setup
  97. * as follows:
  98. *
  99. * %g4: vaddr
  100. * %g5: PTE
  101. * %g6: TAG
  102. *
  103. * The sun4v TLB load wants the PTE in %g3 so we fix that
  104. * up here.
  105. */
  106. ba,pt %xcc, sun4v_itlb_load
  107. mov %g5, %g3
  108. /* No valid entry in the page tables, do full fault
  109. * processing.
  110. */
  111. .globl tsb_do_fault
  112. tsb_do_fault:
  113. cmp %g3, FAULT_CODE_DTLB
  114. 661: rdpr %pstate, %g5
  115. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  116. .section .sun4v_2insn_patch, "ax"
  117. .word 661b
  118. nop
  119. nop
  120. .previous
  121. bne,pn %xcc, tsb_do_itlb_fault
  122. nop
  123. tsb_do_dtlb_fault:
  124. rdpr %tl, %g3
  125. cmp %g3, 1
  126. 661: mov TLB_TAG_ACCESS, %g4
  127. ldxa [%g4] ASI_DMMU, %g5
  128. .section .sun4v_2insn_patch, "ax"
  129. .word 661b
  130. mov %g4, %g5
  131. nop
  132. .previous
  133. be,pt %xcc, sparc64_realfault_common
  134. mov FAULT_CODE_DTLB, %g4
  135. ba,pt %xcc, winfix_trampoline
  136. nop
  137. tsb_do_itlb_fault:
  138. rdpr %tpc, %g5
  139. ba,pt %xcc, sparc64_realfault_common
  140. mov FAULT_CODE_ITLB, %g4
  141. .globl sparc64_realfault_common
  142. sparc64_realfault_common:
  143. /* fault code in %g4, fault address in %g5, etrap will
  144. * preserve these two values in %l4 and %l5 respectively
  145. */
  146. ba,pt %xcc, etrap ! Save trap state
  147. 1: rd %pc, %g7 ! ...
  148. stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
  149. stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
  150. call do_sparc64_fault ! Call fault handler
  151. add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
  152. ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
  153. nop ! Delay slot (fill me)
  154. winfix_trampoline:
  155. rdpr %tpc, %g3 ! Prepare winfixup TNPC
  156. or %g3, 0x7c, %g3 ! Compute branch offset
  157. wrpr %g3, %tnpc ! Write it into TNPC
  158. done ! Trap return
  159. /* Insert an entry into the TSB.
  160. *
  161. * %o0: TSB entry pointer (virt or phys address)
  162. * %o1: tag
  163. * %o2: pte
  164. */
  165. .align 32
  166. .globl __tsb_insert
  167. __tsb_insert:
  168. rdpr %pstate, %o5
  169. wrpr %o5, PSTATE_IE, %pstate
  170. TSB_LOCK_TAG(%o0, %g2, %g3)
  171. TSB_WRITE(%o0, %o2, %o1)
  172. wrpr %o5, %pstate
  173. retl
  174. nop
  175. /* Flush the given TSB entry if it has the matching
  176. * tag.
  177. *
  178. * %o0: TSB entry pointer (virt or phys address)
  179. * %o1: tag
  180. */
  181. .align 32
  182. .globl tsb_flush
  183. tsb_flush:
  184. sethi %hi(TSB_TAG_LOCK_HIGH), %g2
  185. 1: TSB_LOAD_TAG(%o0, %g1)
  186. srlx %g1, 32, %o3
  187. andcc %o3, %g2, %g0
  188. bne,pn %icc, 1b
  189. membar #LoadLoad
  190. cmp %g1, %o1
  191. bne,pt %xcc, 2f
  192. clr %o3
  193. TSB_CAS_TAG(%o0, %g1, %o3)
  194. cmp %g1, %o3
  195. bne,pn %xcc, 1b
  196. nop
  197. 2: retl
  198. TSB_MEMBAR
  199. /* Reload MMU related context switch state at
  200. * schedule() time.
  201. *
  202. * %o0: page table physical address
  203. * %o1: TSB register value
  204. * %o2: TSB virtual address
  205. * %o3: TSB mapping locked PTE
  206. *
  207. * We have to run this whole thing with interrupts
  208. * disabled so that the current cpu doesn't change
  209. * due to preemption.
  210. */
  211. .align 32
  212. .globl __tsb_context_switch
  213. __tsb_context_switch:
  214. rdpr %pstate, %o5
  215. wrpr %o5, PSTATE_IE, %pstate
  216. ldub [%g6 + TI_CPU], %g1
  217. sethi %hi(trap_block), %g2
  218. sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
  219. or %g2, %lo(trap_block), %g2
  220. add %g2, %g1, %g2
  221. stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
  222. 661: mov TSB_REG, %g1
  223. stxa %o1, [%g1] ASI_DMMU
  224. .section .sun4v_2insn_patch, "ax"
  225. .word 661b
  226. mov SCRATCHPAD_UTSBREG1, %g1
  227. stxa %o1, [%g1] ASI_SCRATCHPAD
  228. .previous
  229. membar #Sync
  230. 661: stxa %o1, [%g1] ASI_IMMU
  231. membar #Sync
  232. .section .sun4v_2insn_patch, "ax"
  233. .word 661b
  234. nop
  235. nop
  236. .previous
  237. brz %o2, 9f
  238. nop
  239. sethi %hi(sparc64_highest_unlocked_tlb_ent), %o4
  240. mov TLB_TAG_ACCESS, %g1
  241. lduw [%o4 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
  242. stxa %o2, [%g1] ASI_DMMU
  243. membar #Sync
  244. sllx %g2, 3, %g2
  245. stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
  246. membar #Sync
  247. 9:
  248. wrpr %o5, %pstate
  249. retl
  250. nop