tsb.S 6.2 KB

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