sun4v_tlb_miss.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. #ifdef CONFIG_HUGETLB_PAGE
  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, 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. sethi %hi(sun4v_err_itlb_vaddr), %g1
  169. stx %g4, [%g1 + %lo(sun4v_err_itlb_vaddr)]
  170. sethi %hi(sun4v_err_itlb_ctx), %g1
  171. ldxa [%g0] ASI_SCRATCHPAD, %g6
  172. ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1
  173. stx %o1, [%g1 + %lo(sun4v_err_itlb_ctx)]
  174. sethi %hi(sun4v_err_itlb_pte), %g1
  175. stx %g3, [%g1 + %lo(sun4v_err_itlb_pte)]
  176. sethi %hi(sun4v_err_itlb_error), %g1
  177. stx %o0, [%g1 + %lo(sun4v_err_itlb_error)]
  178. rdpr %tl, %g4
  179. cmp %g4, 1
  180. ble,pt %icc, 1f
  181. sethi %hi(2f), %g7
  182. ba,pt %xcc, etraptl1
  183. or %g7, %lo(2f), %g7
  184. 1: ba,pt %xcc, etrap
  185. 2: or %g7, %lo(2b), %g7
  186. mov %l4, %o1
  187. call sun4v_itlb_error_report
  188. add %sp, PTREGS_OFF, %o0
  189. /* NOTREACHED */
  190. sun4v_dtlb_error:
  191. sethi %hi(sun4v_err_dtlb_vaddr), %g1
  192. stx %g4, [%g1 + %lo(sun4v_err_dtlb_vaddr)]
  193. sethi %hi(sun4v_err_dtlb_ctx), %g1
  194. ldxa [%g0] ASI_SCRATCHPAD, %g6
  195. ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1
  196. stx %o1, [%g1 + %lo(sun4v_err_dtlb_ctx)]
  197. sethi %hi(sun4v_err_dtlb_pte), %g1
  198. stx %g3, [%g1 + %lo(sun4v_err_dtlb_pte)]
  199. sethi %hi(sun4v_err_dtlb_error), %g1
  200. stx %o0, [%g1 + %lo(sun4v_err_dtlb_error)]
  201. rdpr %tl, %g4
  202. cmp %g4, 1
  203. ble,pt %icc, 1f
  204. sethi %hi(2f), %g7
  205. ba,pt %xcc, etraptl1
  206. or %g7, %lo(2f), %g7
  207. 1: ba,pt %xcc, etrap
  208. 2: or %g7, %lo(2b), %g7
  209. mov %l4, %o1
  210. call sun4v_dtlb_error_report
  211. add %sp, PTREGS_OFF, %o0
  212. /* NOTREACHED */
  213. /* Instruction Access Exception, tl0. */
  214. sun4v_iacc:
  215. ldxa [%g0] ASI_SCRATCHPAD, %g2
  216. ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
  217. ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
  218. ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
  219. sllx %g3, 16, %g3
  220. or %g5, %g3, %g5
  221. ba,pt %xcc, etrap
  222. rd %pc, %g7
  223. mov %l4, %o1
  224. mov %l5, %o2
  225. call sun4v_insn_access_exception
  226. add %sp, PTREGS_OFF, %o0
  227. ba,a,pt %xcc, rtrap
  228. /* Instruction Access Exception, tl1. */
  229. sun4v_iacc_tl1:
  230. ldxa [%g0] ASI_SCRATCHPAD, %g2
  231. ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
  232. ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
  233. ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
  234. sllx %g3, 16, %g3
  235. or %g5, %g3, %g5
  236. ba,pt %xcc, etraptl1
  237. rd %pc, %g7
  238. mov %l4, %o1
  239. mov %l5, %o2
  240. call sun4v_insn_access_exception_tl1
  241. add %sp, PTREGS_OFF, %o0
  242. ba,a,pt %xcc, rtrap
  243. /* Data Access Exception, tl0. */
  244. sun4v_dacc:
  245. ldxa [%g0] ASI_SCRATCHPAD, %g2
  246. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  247. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  248. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  249. sllx %g3, 16, %g3
  250. or %g5, %g3, %g5
  251. ba,pt %xcc, etrap
  252. rd %pc, %g7
  253. mov %l4, %o1
  254. mov %l5, %o2
  255. call sun4v_data_access_exception
  256. add %sp, PTREGS_OFF, %o0
  257. ba,a,pt %xcc, rtrap
  258. /* Data Access Exception, tl1. */
  259. sun4v_dacc_tl1:
  260. ldxa [%g0] ASI_SCRATCHPAD, %g2
  261. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  262. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  263. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  264. sllx %g3, 16, %g3
  265. or %g5, %g3, %g5
  266. ba,pt %xcc, etraptl1
  267. rd %pc, %g7
  268. mov %l4, %o1
  269. mov %l5, %o2
  270. call sun4v_data_access_exception_tl1
  271. add %sp, PTREGS_OFF, %o0
  272. ba,a,pt %xcc, rtrap
  273. /* Memory Address Unaligned. */
  274. sun4v_mna:
  275. /* Window fixup? */
  276. rdpr %tl, %g2
  277. cmp %g2, 1
  278. ble,pt %icc, 1f
  279. nop
  280. SET_GL(1)
  281. ldxa [%g0] ASI_SCRATCHPAD, %g2
  282. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g5
  283. mov HV_FAULT_TYPE_UNALIGNED, %g3
  284. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g4
  285. sllx %g3, 16, %g3
  286. or %g4, %g3, %g4
  287. ba,pt %xcc, winfix_mna
  288. rdpr %tpc, %g3
  289. /* not reached */
  290. 1: ldxa [%g0] ASI_SCRATCHPAD, %g2
  291. mov HV_FAULT_TYPE_UNALIGNED, %g3
  292. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  293. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  294. sllx %g3, 16, %g3
  295. or %g5, %g3, %g5
  296. ba,pt %xcc, etrap
  297. rd %pc, %g7
  298. mov %l4, %o1
  299. mov %l5, %o2
  300. call sun4v_do_mna
  301. add %sp, PTREGS_OFF, %o0
  302. ba,a,pt %xcc, rtrap
  303. /* Privileged Action. */
  304. sun4v_privact:
  305. ba,pt %xcc, etrap
  306. rd %pc, %g7
  307. call do_privact
  308. add %sp, PTREGS_OFF, %o0
  309. ba,a,pt %xcc, rtrap
  310. /* Unaligned ldd float, tl0. */
  311. sun4v_lddfmna:
  312. ldxa [%g0] ASI_SCRATCHPAD, %g2
  313. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  314. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  315. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  316. sllx %g3, 16, %g3
  317. or %g5, %g3, %g5
  318. ba,pt %xcc, etrap
  319. rd %pc, %g7
  320. mov %l4, %o1
  321. mov %l5, %o2
  322. call handle_lddfmna
  323. add %sp, PTREGS_OFF, %o0
  324. ba,a,pt %xcc, rtrap
  325. /* Unaligned std float, tl0. */
  326. sun4v_stdfmna:
  327. ldxa [%g0] ASI_SCRATCHPAD, %g2
  328. ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
  329. ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
  330. ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
  331. sllx %g3, 16, %g3
  332. or %g5, %g3, %g5
  333. ba,pt %xcc, etrap
  334. rd %pc, %g7
  335. mov %l4, %o1
  336. mov %l5, %o2
  337. call handle_stdfmna
  338. add %sp, PTREGS_OFF, %o0
  339. ba,a,pt %xcc, rtrap
  340. #define BRANCH_ALWAYS 0x10680000
  341. #define NOP 0x01000000
  342. #define SUN4V_DO_PATCH(OLD, NEW) \
  343. sethi %hi(NEW), %g1; \
  344. or %g1, %lo(NEW), %g1; \
  345. sethi %hi(OLD), %g2; \
  346. or %g2, %lo(OLD), %g2; \
  347. sub %g1, %g2, %g1; \
  348. sethi %hi(BRANCH_ALWAYS), %g3; \
  349. sll %g1, 11, %g1; \
  350. srl %g1, 11 + 2, %g1; \
  351. or %g3, %lo(BRANCH_ALWAYS), %g3; \
  352. or %g3, %g1, %g3; \
  353. stw %g3, [%g2]; \
  354. sethi %hi(NOP), %g3; \
  355. or %g3, %lo(NOP), %g3; \
  356. stw %g3, [%g2 + 0x4]; \
  357. flush %g2;
  358. .globl sun4v_patch_tlb_handlers
  359. .type sun4v_patch_tlb_handlers,#function
  360. sun4v_patch_tlb_handlers:
  361. SUN4V_DO_PATCH(tl0_iamiss, sun4v_itlb_miss)
  362. SUN4V_DO_PATCH(tl1_iamiss, sun4v_itlb_miss)
  363. SUN4V_DO_PATCH(tl0_damiss, sun4v_dtlb_miss)
  364. SUN4V_DO_PATCH(tl1_damiss, sun4v_dtlb_miss)
  365. SUN4V_DO_PATCH(tl0_daprot, sun4v_dtlb_prot)
  366. SUN4V_DO_PATCH(tl1_daprot, sun4v_dtlb_prot)
  367. SUN4V_DO_PATCH(tl0_iax, sun4v_iacc)
  368. SUN4V_DO_PATCH(tl1_iax, sun4v_iacc_tl1)
  369. SUN4V_DO_PATCH(tl0_dax, sun4v_dacc)
  370. SUN4V_DO_PATCH(tl1_dax, sun4v_dacc_tl1)
  371. SUN4V_DO_PATCH(tl0_mna, sun4v_mna)
  372. SUN4V_DO_PATCH(tl1_mna, sun4v_mna)
  373. SUN4V_DO_PATCH(tl0_lddfmna, sun4v_lddfmna)
  374. SUN4V_DO_PATCH(tl0_stdfmna, sun4v_stdfmna)
  375. SUN4V_DO_PATCH(tl0_privact, sun4v_privact)
  376. retl
  377. nop
  378. .size sun4v_patch_tlb_handlers,.-sun4v_patch_tlb_handlers