ktlb.S 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. /* sun4v_itlb_miss branches here with the missing virtual
  20. * address already loaded into %g4
  21. */
  22. kvmap_itlb_4v:
  23. /* Catch kernel NULL pointer calls. */
  24. sethi %hi(PAGE_SIZE), %g5
  25. cmp %g4, %g5
  26. blu,pn %xcc, kvmap_itlb_longpath
  27. nop
  28. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
  29. kvmap_itlb_tsb_miss:
  30. sethi %hi(LOW_OBP_ADDRESS), %g5
  31. cmp %g4, %g5
  32. blu,pn %xcc, kvmap_itlb_vmalloc_addr
  33. mov 0x1, %g5
  34. sllx %g5, 32, %g5
  35. cmp %g4, %g5
  36. blu,pn %xcc, kvmap_itlb_obp
  37. nop
  38. kvmap_itlb_vmalloc_addr:
  39. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
  40. TSB_LOCK_TAG(%g1, %g2, %g7)
  41. /* Load and check PTE. */
  42. ldxa [%g5] ASI_PHYS_USE_EC, %g5
  43. mov 1, %g7
  44. sllx %g7, TSB_TAG_INVALID_BIT, %g7
  45. brgez,a,pn %g5, kvmap_itlb_longpath
  46. TSB_STORE(%g1, %g7)
  47. TSB_WRITE(%g1, %g5, %g6)
  48. /* fallthrough to TLB load */
  49. kvmap_itlb_load:
  50. 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
  51. retry
  52. .section .sun4v_2insn_patch, "ax"
  53. .word 661b
  54. nop
  55. nop
  56. .previous
  57. /* For sun4v the ASI_ITLB_DATA_IN store and the retry
  58. * instruction get nop'd out and we get here to branch
  59. * to the sun4v tlb load code. The registers are setup
  60. * as follows:
  61. *
  62. * %g4: vaddr
  63. * %g5: PTE
  64. * %g6: TAG
  65. *
  66. * The sun4v TLB load wants the PTE in %g3 so we fix that
  67. * up here.
  68. */
  69. ba,pt %xcc, sun4v_itlb_load
  70. mov %g5, %g3
  71. kvmap_itlb_longpath:
  72. 661: rdpr %pstate, %g5
  73. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  74. .section .sun4v_2insn_patch, "ax"
  75. .word 661b
  76. SET_GL(1)
  77. nop
  78. .previous
  79. rdpr %tpc, %g5
  80. ba,pt %xcc, sparc64_realfault_common
  81. mov FAULT_CODE_ITLB, %g4
  82. kvmap_itlb_obp:
  83. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
  84. TSB_LOCK_TAG(%g1, %g2, %g7)
  85. TSB_WRITE(%g1, %g5, %g6)
  86. ba,pt %xcc, kvmap_itlb_load
  87. nop
  88. kvmap_dtlb_obp:
  89. OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
  90. TSB_LOCK_TAG(%g1, %g2, %g7)
  91. TSB_WRITE(%g1, %g5, %g6)
  92. ba,pt %xcc, kvmap_dtlb_load
  93. nop
  94. .align 32
  95. kvmap_dtlb_tsb4m_load:
  96. TSB_LOCK_TAG(%g1, %g2, %g7)
  97. TSB_WRITE(%g1, %g5, %g6)
  98. ba,pt %xcc, kvmap_dtlb_load
  99. nop
  100. kvmap_dtlb:
  101. /* %g6: TAG TARGET */
  102. mov TLB_TAG_ACCESS, %g4
  103. ldxa [%g4] ASI_DMMU, %g4
  104. /* sun4v_dtlb_miss branches here with the missing virtual
  105. * address already loaded into %g4
  106. */
  107. kvmap_dtlb_4v:
  108. brgez,pn %g4, kvmap_dtlb_nonlinear
  109. nop
  110. #ifdef CONFIG_DEBUG_PAGEALLOC
  111. /* Index through the base page size TSB even for linear
  112. * mappings when using page allocation debugging.
  113. */
  114. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  115. #else
  116. /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
  117. KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  118. #endif
  119. /* TSB entry address left in %g1, lookup linear PTE.
  120. * Must preserve %g1 and %g6 (TAG).
  121. */
  122. kvmap_dtlb_tsb4m_miss:
  123. /* Clear the PAGE_OFFSET top virtual bits, shift
  124. * down to get PFN, and make sure PFN is in range.
  125. */
  126. 661: sllx %g4, 0, %g5
  127. .section .page_offset_shift_patch, "ax"
  128. .word 661b
  129. .previous
  130. /* Check to see if we know about valid memory at the 4MB
  131. * chunk this physical address will reside within.
  132. */
  133. 661: srlx %g5, MAX_PHYS_ADDRESS_BITS, %g2
  134. .section .page_offset_shift_patch, "ax"
  135. .word 661b
  136. .previous
  137. brnz,pn %g2, kvmap_dtlb_longpath
  138. nop
  139. /* This unconditional branch and delay-slot nop gets patched
  140. * by the sethi sequence once the bitmap is properly setup.
  141. */
  142. .globl valid_addr_bitmap_insn
  143. valid_addr_bitmap_insn:
  144. ba,pt %xcc, 2f
  145. nop
  146. .subsection 2
  147. .globl valid_addr_bitmap_patch
  148. valid_addr_bitmap_patch:
  149. sethi %hi(sparc64_valid_addr_bitmap), %g7
  150. or %g7, %lo(sparc64_valid_addr_bitmap), %g7
  151. .previous
  152. 661: srlx %g5, ILOG2_4MB, %g2
  153. .section .page_offset_shift_patch, "ax"
  154. .word 661b
  155. .previous
  156. srlx %g2, 6, %g5
  157. and %g2, 63, %g2
  158. sllx %g5, 3, %g5
  159. ldx [%g7 + %g5], %g5
  160. mov 1, %g7
  161. sllx %g7, %g2, %g7
  162. andcc %g5, %g7, %g0
  163. be,pn %xcc, kvmap_dtlb_longpath
  164. 2: sethi %hi(kpte_linear_bitmap), %g2
  165. /* Get the 256MB physical address index. */
  166. 661: sllx %g4, 0, %g5
  167. .section .page_offset_shift_patch, "ax"
  168. .word 661b
  169. .previous
  170. or %g2, %lo(kpte_linear_bitmap), %g2
  171. 661: srlx %g5, ILOG2_256MB, %g5
  172. .section .page_offset_shift_patch, "ax"
  173. .word 661b
  174. .previous
  175. and %g5, (32 - 1), %g7
  176. /* Divide by 32 to get the offset into the bitmask. */
  177. srlx %g5, 5, %g5
  178. add %g7, %g7, %g7
  179. sllx %g5, 3, %g5
  180. /* kern_linear_pte_xor[(mask >> shift) & 3)] */
  181. ldx [%g2 + %g5], %g2
  182. srlx %g2, %g7, %g7
  183. sethi %hi(kern_linear_pte_xor), %g5
  184. and %g7, 3, %g7
  185. or %g5, %lo(kern_linear_pte_xor), %g5
  186. sllx %g7, 3, %g7
  187. ldx [%g5 + %g7], %g2
  188. .globl kvmap_linear_patch
  189. kvmap_linear_patch:
  190. ba,pt %xcc, kvmap_dtlb_tsb4m_load
  191. xor %g2, %g4, %g5
  192. kvmap_dtlb_vmalloc_addr:
  193. KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
  194. TSB_LOCK_TAG(%g1, %g2, %g7)
  195. /* Load and check PTE. */
  196. ldxa [%g5] ASI_PHYS_USE_EC, %g5
  197. mov 1, %g7
  198. sllx %g7, TSB_TAG_INVALID_BIT, %g7
  199. brgez,a,pn %g5, kvmap_dtlb_longpath
  200. TSB_STORE(%g1, %g7)
  201. TSB_WRITE(%g1, %g5, %g6)
  202. /* fallthrough to TLB load */
  203. kvmap_dtlb_load:
  204. 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
  205. retry
  206. .section .sun4v_2insn_patch, "ax"
  207. .word 661b
  208. nop
  209. nop
  210. .previous
  211. /* For sun4v the ASI_DTLB_DATA_IN store and the retry
  212. * instruction get nop'd out and we get here to branch
  213. * to the sun4v tlb load code. The registers are setup
  214. * as follows:
  215. *
  216. * %g4: vaddr
  217. * %g5: PTE
  218. * %g6: TAG
  219. *
  220. * The sun4v TLB load wants the PTE in %g3 so we fix that
  221. * up here.
  222. */
  223. ba,pt %xcc, sun4v_dtlb_load
  224. mov %g5, %g3
  225. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  226. kvmap_vmemmap:
  227. sub %g4, %g5, %g5
  228. srlx %g5, 22, %g5
  229. sethi %hi(vmemmap_table), %g1
  230. sllx %g5, 3, %g5
  231. or %g1, %lo(vmemmap_table), %g1
  232. ba,pt %xcc, kvmap_dtlb_load
  233. ldx [%g1 + %g5], %g5
  234. #endif
  235. kvmap_dtlb_nonlinear:
  236. /* Catch kernel NULL pointer derefs. */
  237. sethi %hi(PAGE_SIZE), %g5
  238. cmp %g4, %g5
  239. bleu,pn %xcc, kvmap_dtlb_longpath
  240. nop
  241. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  242. /* Do not use the TSB for vmemmap. */
  243. mov (VMEMMAP_BASE >> 40), %g5
  244. sllx %g5, 40, %g5
  245. cmp %g4,%g5
  246. bgeu,pn %xcc, kvmap_vmemmap
  247. nop
  248. #endif
  249. KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
  250. kvmap_dtlb_tsbmiss:
  251. sethi %hi(MODULES_VADDR), %g5
  252. cmp %g4, %g5
  253. blu,pn %xcc, kvmap_dtlb_longpath
  254. mov (VMALLOC_END >> 40), %g5
  255. sllx %g5, 40, %g5
  256. cmp %g4, %g5
  257. bgeu,pn %xcc, kvmap_dtlb_longpath
  258. nop
  259. kvmap_check_obp:
  260. sethi %hi(LOW_OBP_ADDRESS), %g5
  261. cmp %g4, %g5
  262. blu,pn %xcc, kvmap_dtlb_vmalloc_addr
  263. mov 0x1, %g5
  264. sllx %g5, 32, %g5
  265. cmp %g4, %g5
  266. blu,pn %xcc, kvmap_dtlb_obp
  267. nop
  268. ba,pt %xcc, kvmap_dtlb_vmalloc_addr
  269. nop
  270. kvmap_dtlb_longpath:
  271. 661: rdpr %pstate, %g5
  272. wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
  273. .section .sun4v_2insn_patch, "ax"
  274. .word 661b
  275. SET_GL(1)
  276. ldxa [%g0] ASI_SCRATCHPAD, %g5
  277. .previous
  278. rdpr %tl, %g3
  279. cmp %g3, 1
  280. 661: mov TLB_TAG_ACCESS, %g4
  281. ldxa [%g4] ASI_DMMU, %g5
  282. .section .sun4v_2insn_patch, "ax"
  283. .word 661b
  284. ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
  285. nop
  286. .previous
  287. be,pt %xcc, sparc64_realfault_common
  288. mov FAULT_CODE_DTLB, %g4
  289. ba,pt %xcc, winfix_trampoline
  290. nop