sun4v_tlb_miss.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /* sun4v_tlb_miss.S: Sun4v TLB miss handlers.
  2. *
  3. * Copyright (C) 2006 <davem@davemloft.net>
  4. */
  5. .text
  6. .align 32
  7. /* Load ITLB fault information into VADDR and CTX, using BASE. */
  8. #define LOAD_ITLB_INFO(BASE, VADDR, CTX) \
  9. ldx [BASE + HV_FAULT_I_ADDR_OFFSET], VADDR; \
  10. ldx [BASE + HV_FAULT_I_CTX_OFFSET], CTX;
  11. /* Load DTLB fault information into VADDR and CTX, using BASE. */
  12. #define LOAD_DTLB_INFO(BASE, VADDR, CTX) \
  13. ldx [BASE + HV_FAULT_D_ADDR_OFFSET], VADDR; \
  14. ldx [BASE + HV_FAULT_D_CTX_OFFSET], CTX;
  15. /* DEST = (VADDR >> 22)
  16. *
  17. * Branch to ZERO_CTX_LABEL if context is zero.
  18. */
  19. #define COMPUTE_TAG_TARGET(DEST, VADDR, CTX, ZERO_CTX_LABEL) \
  20. srlx VADDR, 22, DEST; \
  21. brz,pn CTX, ZERO_CTX_LABEL; \
  22. nop;
  23. /* Create TSB pointer. This is something like:
  24. *
  25. * index_mask = (512 << (tsb_reg & 0x7UL)) - 1UL;
  26. * tsb_base = tsb_reg & ~0x7UL;
  27. * tsb_index = ((vaddr >> HASH_SHIFT) & tsb_mask);
  28. * tsb_ptr = tsb_base + (tsb_index * 16);
  29. */
  30. #define COMPUTE_TSB_PTR(TSB_PTR, VADDR, HASH_SHIFT, TMP1, TMP2) \
  31. and TSB_PTR, 0x7, TMP1; \
  32. mov 512, TMP2; \
  33. andn TSB_PTR, 0x7, TSB_PTR; \
  34. sllx TMP2, TMP1, TMP2; \
  35. srlx VADDR, HASH_SHIFT, TMP1; \
  36. sub TMP2, 1, TMP2; \
  37. and TMP1, TMP2, TMP1; \
  38. sllx TMP1, 4, TMP1; \
  39. add TSB_PTR, TMP1, TSB_PTR;
  40. sun4v_itlb_miss:
  41. /* Load MMU Miss base into %g2. */
  42. ldxa [%g0] ASI_SCRATCHPAD, %g2
  43. /* Load UTSB reg into %g1. */
  44. mov SCRATCHPAD_UTSBREG1, %g1
  45. ldxa [%g1] ASI_SCRATCHPAD, %g1
  46. LOAD_ITLB_INFO(%g2, %g4, %g5)
  47. COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_itlb_4v)
  48. COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g3, %g7)
  49. /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
  50. ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
  51. cmp %g2, %g6
  52. bne,a,pn %xcc, tsb_miss_page_table_walk
  53. mov FAULT_CODE_ITLB, %g3
  54. andcc %g3, _PAGE_EXEC_4V, %g0
  55. be,a,pn %xcc, tsb_do_fault
  56. mov FAULT_CODE_ITLB, %g3
  57. /* We have a valid entry, make hypervisor call to load
  58. * I-TLB and return from trap.
  59. *
  60. * %g3: PTE
  61. * %g4: vaddr
  62. */
  63. sun4v_itlb_load:
  64. ldxa [%g0] ASI_SCRATCHPAD, %g6
  65. mov %o0, %g1 ! save %o0
  66. mov %o1, %g2 ! save %o1
  67. mov %o2, %g5 ! save %o2
  68. mov %o3, %g7 ! save %o3
  69. mov %g4, %o0 ! vaddr
  70. ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1 ! ctx
  71. mov %g3, %o2 ! PTE
  72. mov HV_MMU_IMMU, %o3 ! flags
  73. ta HV_MMU_MAP_ADDR_TRAP
  74. brnz,pn %o0, sun4v_itlb_error
  75. mov %g2, %o1 ! restore %o1
  76. mov %g1, %o0 ! restore %o0
  77. mov %g5, %o2 ! restore %o2
  78. mov %g7, %o3 ! restore %o3
  79. retry
  80. sun4v_dtlb_miss:
  81. /* Load MMU Miss base into %g2. */
  82. ldxa [%g0] ASI_SCRATCHPAD, %g2
  83. /* Load UTSB reg into %g1. */
  84. mov SCRATCHPAD_UTSBREG1, %g1
  85. ldxa [%g1] ASI_SCRATCHPAD, %g1
  86. LOAD_DTLB_INFO(%g2, %g4, %g5)
  87. COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_dtlb_4v)
  88. COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g3, %g7)
  89. /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
  90. ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
  91. cmp %g2, %g6
  92. bne,a,pn %xcc, tsb_miss_page_table_walk
  93. mov FAULT_CODE_DTLB, %g3
  94. /* We have a valid entry, make hypervisor call to load
  95. * D-TLB and return from trap.
  96. *
  97. * %g3: PTE
  98. * %g4: vaddr
  99. */
  100. sun4v_dtlb_load:
  101. ldxa [%g0] ASI_SCRATCHPAD, %g6
  102. mov %o0, %g1 ! save %o0
  103. mov %o1, %g2 ! save %o1
  104. mov %o2, %g5 ! save %o2
  105. mov %o3, %g7 ! save %o3
  106. mov %g4, %o0 ! vaddr
  107. ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1 ! ctx
  108. mov %g3, %o2 ! PTE
  109. mov HV_MMU_DMMU, %o3 ! flags
  110. ta HV_MMU_MAP_ADDR_TRAP
  111. brnz,pn %o0, sun4v_dtlb_error
  112. mov %g2, %o1 ! restore %o1
  113. mov %g1, %o0 ! restore %o0
  114. mov %g5, %o2 ! restore %o2
  115. mov %g7, %o3 ! restore %o3
  116. retry
  117. sun4v_dtlb_prot:
  118. SET_GL(1)
  119. /* Load MMU Miss base into %g5. */
  120. ldxa [%g0] ASI_SCRATCHPAD, %g5
  121. ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
  122. rdpr %tl, %g1
  123. cmp %g1, 1
  124. bgu,pn %xcc, winfix_trampoline
  125. mov FAULT_CODE_DTLB | FAULT_CODE_WRITE, %g4
  126. ba,pt %xcc, sparc64_realfault_common
  127. nop
  128. /* Called from trap table:
  129. * %g4: vaddr
  130. * %g5: context
  131. * %g6: TAG TARGET
  132. */
  133. sun4v_itsb_miss:
  134. mov SCRATCHPAD_UTSBREG1, %g1
  135. ldxa [%g1] ASI_SCRATCHPAD, %g1
  136. brz,pn %g5, kvmap_itlb_4v
  137. mov FAULT_CODE_ITLB, %g3
  138. ba,a,pt %xcc, sun4v_tsb_miss_common
  139. /* Called from trap table:
  140. * %g4: vaddr
  141. * %g5: context
  142. * %g6: TAG TARGET
  143. */
  144. sun4v_dtsb_miss:
  145. mov SCRATCHPAD_UTSBREG1, %g1
  146. ldxa [%g1] ASI_SCRATCHPAD, %g1
  147. brz,pn %g5, kvmap_dtlb_4v
  148. mov FAULT_CODE_DTLB, %g3
  149. /* fallthrough */
  150. sun4v_tsb_miss_common:
  151. COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g5, %g7)
  152. sub %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  153. #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
  154. mov SCRATCHPAD_UTSBREG2, %g5
  155. ldxa [%g5] ASI_SCRATCHPAD, %g5
  156. cmp %g5, -1
  157. be,pt %xcc, 80f
  158. nop
  159. COMPUTE_TSB_PTR(%g5, %g4, REAL_HPAGE_SHIFT, %g2, %g7)
  160. /* That clobbered %g2, reload it. */
  161. ldxa [%g0] ASI_SCRATCHPAD, %g2
  162. sub %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  163. 80: stx %g5, [%g2 + TRAP_PER_CPU_TSB_HUGE_TEMP]
  164. #endif
  165. ba,pt %xcc, tsb_miss_page_table_walk_sun4v_fastpath
  166. ldx [%g2 + TRAP_PER_CPU_PGD_PADDR], %g7
  167. sun4v_itlb_error:
  168. rdpr %tl, %g1
  169. cmp %g1, 1
  170. ble,pt %icc, sun4v_bad_ra
  171. or %g0, FAULT_CODE_BAD_RA | FAULT_CODE_ITLB, %g1
  172. sethi %hi(sun4v_err_itlb_vaddr), %g1
  173. stx %g4, [%g1 + %lo(sun4v_err_itlb_vaddr)]
  174. sethi %hi(sun4v_err_itlb_ctx), %g1
  175. ldxa [%g0] ASI_SCRATCHPAD, %g6
  176. ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1
  177. stx %o1, [%g1 + %lo(sun4v_err_itlb_ctx)]
  178. sethi %hi(sun4v_err_itlb_pte), %g1
  179. stx %g3, [%g1 + %lo(sun4v_err_itlb_pte)]
  180. sethi %hi(sun4v_err_itlb_error), %g1
  181. stx %o0, [%g1 + %lo(sun4v_err_itlb_error)]
  182. sethi %hi(1f), %g7
  183. rdpr %tl, %g4
  184. ba,pt %xcc, etraptl1
  185. 1: or %g7, %lo(1f), %g7
  186. mov %l4, %o1
  187. call sun4v_itlb_error_report
  188. add %sp, PTREGS_OFF, %o0
  189. /* NOTREACHED */
  190. sun4v_dtlb_error:
  191. rdpr %tl, %g1
  192. cmp %g1, 1
  193. ble,pt %icc, sun4v_bad_ra
  194. or %g0, FAULT_CODE_BAD_RA | FAULT_CODE_DTLB, %g1
  195. sethi %hi(sun4v_err_dtlb_vaddr), %g1
  196. stx %g4, [%g1 + %lo(sun4v_err_dtlb_vaddr)]
  197. sethi %hi(sun4v_err_dtlb_ctx), %g1
  198. ldxa [%g0] ASI_SCRATCHPAD, %g6
  199. ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1
  200. stx %o1, [%g1 + %lo(sun4v_err_dtlb_ctx)]
  201. sethi %hi(sun4v_err_dtlb_pte), %g1
  202. stx %g3, [%g1 + %lo(sun4v_err_dtlb_pte)]
  203. sethi %hi(sun4v_err_dtlb_error), %g1
  204. stx %o0, [%g1 + %lo(sun4v_err_dtlb_error)]
  205. sethi %hi(1f), %g7
  206. rdpr %tl, %g4
  207. ba,pt %xcc, etraptl1
  208. 1: or %g7, %lo(1f), %g7
  209. mov %l4, %o1
  210. call sun4v_dtlb_error_report
  211. add %sp, PTREGS_OFF, %o0
  212. /* NOTREACHED */
  213. sun4v_bad_ra:
  214. or %g0, %g4, %g5
  215. ba,pt %xcc, sparc64_realfault_common
  216. or %g1, %g0, %g4
  217. /* NOTREACHED */
  218. /* Instruction Access Exception, tl0. */
  219. sun4v_iacc:
  220. ldxa [%g0] ASI_SCRATCHPAD, %g2
  221. ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
  222. ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
  223. ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
  224. sllx %g3, 16, %g3
  225. or %g5, %g3, %g5
  226. ba,pt %xcc, etrap
  227. rd %pc, %g7
  228. mov %l4, %o1
  229. mov %l5, %o2
  230. call sun4v_insn_access_exception
  231. add %sp, PTREGS_OFF, %o0
  232. ba,a,pt %xcc, rtrap
  233. /* Instruction Access Exception, tl1. */
  234. sun4v_iacc_tl1:
  235. ldxa [%g0] ASI_SCRATCHPAD, %g2
  236. ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
  237. ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
  238. ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
  239. sllx %g3, 16, %g3
  240. or %g5, %g3, %g5
  241. ba,pt %xcc, etraptl1
  242. rd %pc, %g7
  243. mov %l4, %o1
  244. mov %l5, %o2
  245. call sun4v_insn_access_exception_tl1
  246. add %sp, PTREGS_OFF, %o0
  247. ba,a,pt %xcc, rtrap
  248. /* Data Access Exception, tl0. */
  249. sun4v_dacc:
  250. ldxa [%g0] ASI_SCRATCHPAD, %g2
  251. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  252. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  253. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  254. sllx %g3, 16, %g3
  255. or %g5, %g3, %g5
  256. ba,pt %xcc, etrap
  257. rd %pc, %g7
  258. mov %l4, %o1
  259. mov %l5, %o2
  260. call sun4v_data_access_exception
  261. add %sp, PTREGS_OFF, %o0
  262. ba,a,pt %xcc, rtrap
  263. /* Data Access Exception, tl1. */
  264. sun4v_dacc_tl1:
  265. ldxa [%g0] ASI_SCRATCHPAD, %g2
  266. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  267. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  268. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  269. sllx %g3, 16, %g3
  270. or %g5, %g3, %g5
  271. ba,pt %xcc, etraptl1
  272. rd %pc, %g7
  273. mov %l4, %o1
  274. mov %l5, %o2
  275. call sun4v_data_access_exception_tl1
  276. add %sp, PTREGS_OFF, %o0
  277. ba,a,pt %xcc, rtrap
  278. /* Memory Address Unaligned. */
  279. sun4v_mna:
  280. /* Window fixup? */
  281. rdpr %tl, %g2
  282. cmp %g2, 1
  283. ble,pt %icc, 1f
  284. nop
  285. SET_GL(1)
  286. ldxa [%g0] ASI_SCRATCHPAD, %g2
  287. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g5
  288. mov HV_FAULT_TYPE_UNALIGNED, %g3
  289. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g4
  290. sllx %g3, 16, %g3
  291. or %g4, %g3, %g4
  292. ba,pt %xcc, winfix_mna
  293. rdpr %tpc, %g3
  294. /* not reached */
  295. 1: ldxa [%g0] ASI_SCRATCHPAD, %g2
  296. mov HV_FAULT_TYPE_UNALIGNED, %g3
  297. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  298. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  299. sllx %g3, 16, %g3
  300. or %g5, %g3, %g5
  301. ba,pt %xcc, etrap
  302. rd %pc, %g7
  303. mov %l4, %o1
  304. mov %l5, %o2
  305. call sun4v_do_mna
  306. add %sp, PTREGS_OFF, %o0
  307. ba,a,pt %xcc, rtrap
  308. /* Privileged Action. */
  309. sun4v_privact:
  310. ba,pt %xcc, etrap
  311. rd %pc, %g7
  312. call do_privact
  313. add %sp, PTREGS_OFF, %o0
  314. ba,a,pt %xcc, rtrap
  315. /* Unaligned ldd float, tl0. */
  316. sun4v_lddfmna:
  317. ldxa [%g0] ASI_SCRATCHPAD, %g2
  318. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  319. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  320. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  321. sllx %g3, 16, %g3
  322. or %g5, %g3, %g5
  323. ba,pt %xcc, etrap
  324. rd %pc, %g7
  325. mov %l4, %o1
  326. mov %l5, %o2
  327. call handle_lddfmna
  328. add %sp, PTREGS_OFF, %o0
  329. ba,a,pt %xcc, rtrap
  330. /* Unaligned std float, tl0. */
  331. sun4v_stdfmna:
  332. ldxa [%g0] ASI_SCRATCHPAD, %g2
  333. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  334. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  335. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  336. sllx %g3, 16, %g3
  337. or %g5, %g3, %g5
  338. ba,pt %xcc, etrap
  339. rd %pc, %g7
  340. mov %l4, %o1
  341. mov %l5, %o2
  342. call handle_stdfmna
  343. add %sp, PTREGS_OFF, %o0
  344. ba,a,pt %xcc, rtrap
  345. #define BRANCH_ALWAYS 0x10680000
  346. #define NOP 0x01000000
  347. #define SUN4V_DO_PATCH(OLD, NEW) \
  348. sethi %hi(NEW), %g1; \
  349. or %g1, %lo(NEW), %g1; \
  350. sethi %hi(OLD), %g2; \
  351. or %g2, %lo(OLD), %g2; \
  352. sub %g1, %g2, %g1; \
  353. sethi %hi(BRANCH_ALWAYS), %g3; \
  354. sll %g1, 11, %g1; \
  355. srl %g1, 11 + 2, %g1; \
  356. or %g3, %lo(BRANCH_ALWAYS), %g3; \
  357. or %g3, %g1, %g3; \
  358. stw %g3, [%g2]; \
  359. sethi %hi(NOP), %g3; \
  360. or %g3, %lo(NOP), %g3; \
  361. stw %g3, [%g2 + 0x4]; \
  362. flush %g2;
  363. .globl sun4v_patch_tlb_handlers
  364. .type sun4v_patch_tlb_handlers,#function
  365. sun4v_patch_tlb_handlers:
  366. SUN4V_DO_PATCH(tl0_iamiss, sun4v_itlb_miss)
  367. SUN4V_DO_PATCH(tl1_iamiss, sun4v_itlb_miss)
  368. SUN4V_DO_PATCH(tl0_damiss, sun4v_dtlb_miss)
  369. SUN4V_DO_PATCH(tl1_damiss, sun4v_dtlb_miss)
  370. SUN4V_DO_PATCH(tl0_daprot, sun4v_dtlb_prot)
  371. SUN4V_DO_PATCH(tl1_daprot, sun4v_dtlb_prot)
  372. SUN4V_DO_PATCH(tl0_iax, sun4v_iacc)
  373. SUN4V_DO_PATCH(tl1_iax, sun4v_iacc_tl1)
  374. SUN4V_DO_PATCH(tl0_dax, sun4v_dacc)
  375. SUN4V_DO_PATCH(tl1_dax, sun4v_dacc_tl1)
  376. SUN4V_DO_PATCH(tl0_mna, sun4v_mna)
  377. SUN4V_DO_PATCH(tl1_mna, sun4v_mna)
  378. SUN4V_DO_PATCH(tl0_lddfmna, sun4v_lddfmna)
  379. SUN4V_DO_PATCH(tl0_stdfmna, sun4v_stdfmna)
  380. SUN4V_DO_PATCH(tl0_privact, sun4v_privact)
  381. retl
  382. nop
  383. .size sun4v_patch_tlb_handlers,.-sun4v_patch_tlb_handlers