tsb.S 6.8 KB

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