ultra.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /* $Id: ultra.S,v 1.72 2002/02/09 19:49:31 davem Exp $
  2. * ultra.S: Don't expand these all over the place...
  3. *
  4. * Copyright (C) 1997, 2000 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/config.h>
  7. #include <asm/asi.h>
  8. #include <asm/pgtable.h>
  9. #include <asm/page.h>
  10. #include <asm/spitfire.h>
  11. #include <asm/mmu_context.h>
  12. #include <asm/mmu.h>
  13. #include <asm/pil.h>
  14. #include <asm/head.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/cacheflush.h>
  17. /* Basically, most of the Spitfire vs. Cheetah madness
  18. * has to do with the fact that Cheetah does not support
  19. * IMMU flushes out of the secondary context. Someone needs
  20. * to throw a south lake birthday party for the folks
  21. * in Microelectronics who refused to fix this shit.
  22. */
  23. /* This file is meant to be read efficiently by the CPU, not humans.
  24. * Staraj sie tego nikomu nie pierdolnac...
  25. */
  26. .text
  27. .align 32
  28. .globl __flush_tlb_mm
  29. __flush_tlb_mm: /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
  30. ldxa [%o1] ASI_DMMU, %g2
  31. cmp %g2, %o0
  32. bne,pn %icc, __spitfire_flush_tlb_mm_slow
  33. mov 0x50, %g3
  34. stxa %g0, [%g3] ASI_DMMU_DEMAP
  35. stxa %g0, [%g3] ASI_IMMU_DEMAP
  36. retl
  37. flush %g6
  38. nop
  39. nop
  40. nop
  41. nop
  42. nop
  43. nop
  44. nop
  45. nop
  46. nop
  47. nop
  48. .align 32
  49. .globl __flush_tlb_pending
  50. __flush_tlb_pending:
  51. /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
  52. rdpr %pstate, %g7
  53. sllx %o1, 3, %o1
  54. andn %g7, PSTATE_IE, %g2
  55. wrpr %g2, %pstate
  56. mov SECONDARY_CONTEXT, %o4
  57. ldxa [%o4] ASI_DMMU, %g2
  58. stxa %o0, [%o4] ASI_DMMU
  59. 1: sub %o1, (1 << 3), %o1
  60. ldx [%o2 + %o1], %o3
  61. andcc %o3, 1, %g0
  62. andn %o3, 1, %o3
  63. be,pn %icc, 2f
  64. or %o3, 0x10, %o3
  65. stxa %g0, [%o3] ASI_IMMU_DEMAP
  66. 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
  67. membar #Sync
  68. brnz,pt %o1, 1b
  69. nop
  70. stxa %g2, [%o4] ASI_DMMU
  71. flush %g6
  72. retl
  73. wrpr %g7, 0x0, %pstate
  74. nop
  75. nop
  76. nop
  77. nop
  78. .align 32
  79. .globl __flush_tlb_kernel_range
  80. __flush_tlb_kernel_range: /* %o0=start, %o1=end */
  81. cmp %o0, %o1
  82. be,pn %xcc, 2f
  83. sethi %hi(PAGE_SIZE), %o4
  84. sub %o1, %o0, %o3
  85. sub %o3, %o4, %o3
  86. or %o0, 0x20, %o0 ! Nucleus
  87. 1: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
  88. stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
  89. membar #Sync
  90. brnz,pt %o3, 1b
  91. sub %o3, %o4, %o3
  92. 2: retl
  93. flush %g6
  94. __spitfire_flush_tlb_mm_slow:
  95. rdpr %pstate, %g1
  96. wrpr %g1, PSTATE_IE, %pstate
  97. stxa %o0, [%o1] ASI_DMMU
  98. stxa %g0, [%g3] ASI_DMMU_DEMAP
  99. stxa %g0, [%g3] ASI_IMMU_DEMAP
  100. flush %g6
  101. stxa %g2, [%o1] ASI_DMMU
  102. flush %g6
  103. retl
  104. wrpr %g1, 0, %pstate
  105. /*
  106. * The following code flushes one page_size worth.
  107. */
  108. #if (PAGE_SHIFT == 13)
  109. #define ITAG_MASK 0xfe
  110. #elif (PAGE_SHIFT == 16)
  111. #define ITAG_MASK 0x7fe
  112. #else
  113. #error unsupported PAGE_SIZE
  114. #endif
  115. .section .kprobes.text, "ax"
  116. .align 32
  117. .globl __flush_icache_page
  118. __flush_icache_page: /* %o0 = phys_page */
  119. membar #StoreStore
  120. srlx %o0, PAGE_SHIFT, %o0
  121. sethi %uhi(PAGE_OFFSET), %g1
  122. sllx %o0, PAGE_SHIFT, %o0
  123. sethi %hi(PAGE_SIZE), %g2
  124. sllx %g1, 32, %g1
  125. add %o0, %g1, %o0
  126. 1: subcc %g2, 32, %g2
  127. bne,pt %icc, 1b
  128. flush %o0 + %g2
  129. retl
  130. nop
  131. #ifdef DCACHE_ALIASING_POSSIBLE
  132. #if (PAGE_SHIFT != 13)
  133. #error only page shift of 13 is supported by dcache flush
  134. #endif
  135. #define DTAG_MASK 0x3
  136. /* This routine is Spitfire specific so the hardcoded
  137. * D-cache size and line-size are OK.
  138. */
  139. .align 64
  140. .globl __flush_dcache_page
  141. __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
  142. sethi %uhi(PAGE_OFFSET), %g1
  143. sllx %g1, 32, %g1
  144. sub %o0, %g1, %o0 ! physical address
  145. srlx %o0, 11, %o0 ! make D-cache TAG
  146. sethi %hi(1 << 14), %o2 ! D-cache size
  147. sub %o2, (1 << 5), %o2 ! D-cache line size
  148. 1: ldxa [%o2] ASI_DCACHE_TAG, %o3 ! load D-cache TAG
  149. andcc %o3, DTAG_MASK, %g0 ! Valid?
  150. be,pn %xcc, 2f ! Nope, branch
  151. andn %o3, DTAG_MASK, %o3 ! Clear valid bits
  152. cmp %o3, %o0 ! TAG match?
  153. bne,pt %xcc, 2f ! Nope, branch
  154. nop
  155. stxa %g0, [%o2] ASI_DCACHE_TAG ! Invalidate TAG
  156. membar #Sync
  157. 2: brnz,pt %o2, 1b
  158. sub %o2, (1 << 5), %o2 ! D-cache line size
  159. /* The I-cache does not snoop local stores so we
  160. * better flush that too when necessary.
  161. */
  162. brnz,pt %o1, __flush_icache_page
  163. sllx %o0, 11, %o0
  164. retl
  165. nop
  166. #endif /* DCACHE_ALIASING_POSSIBLE */
  167. .previous
  168. /* Cheetah specific versions, patched at boot time. */
  169. __cheetah_flush_tlb_mm: /* 18 insns */
  170. rdpr %pstate, %g7
  171. andn %g7, PSTATE_IE, %g2
  172. wrpr %g2, 0x0, %pstate
  173. wrpr %g0, 1, %tl
  174. mov PRIMARY_CONTEXT, %o2
  175. mov 0x40, %g3
  176. ldxa [%o2] ASI_DMMU, %g2
  177. srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o1
  178. sllx %o1, CTX_PGSZ1_NUC_SHIFT, %o1
  179. or %o0, %o1, %o0 /* Preserve nucleus page size fields */
  180. stxa %o0, [%o2] ASI_DMMU
  181. stxa %g0, [%g3] ASI_DMMU_DEMAP
  182. stxa %g0, [%g3] ASI_IMMU_DEMAP
  183. stxa %g2, [%o2] ASI_DMMU
  184. flush %g6
  185. wrpr %g0, 0, %tl
  186. retl
  187. wrpr %g7, 0x0, %pstate
  188. __cheetah_flush_tlb_pending: /* 26 insns */
  189. /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
  190. rdpr %pstate, %g7
  191. sllx %o1, 3, %o1
  192. andn %g7, PSTATE_IE, %g2
  193. wrpr %g2, 0x0, %pstate
  194. wrpr %g0, 1, %tl
  195. mov PRIMARY_CONTEXT, %o4
  196. ldxa [%o4] ASI_DMMU, %g2
  197. srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
  198. sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
  199. or %o0, %o3, %o0 /* Preserve nucleus page size fields */
  200. stxa %o0, [%o4] ASI_DMMU
  201. 1: sub %o1, (1 << 3), %o1
  202. ldx [%o2 + %o1], %o3
  203. andcc %o3, 1, %g0
  204. be,pn %icc, 2f
  205. andn %o3, 1, %o3
  206. stxa %g0, [%o3] ASI_IMMU_DEMAP
  207. 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
  208. membar #Sync
  209. brnz,pt %o1, 1b
  210. nop
  211. stxa %g2, [%o4] ASI_DMMU
  212. flush %g6
  213. wrpr %g0, 0, %tl
  214. retl
  215. wrpr %g7, 0x0, %pstate
  216. #ifdef DCACHE_ALIASING_POSSIBLE
  217. __cheetah_flush_dcache_page: /* 11 insns */
  218. sethi %uhi(PAGE_OFFSET), %g1
  219. sllx %g1, 32, %g1
  220. sub %o0, %g1, %o0
  221. sethi %hi(PAGE_SIZE), %o4
  222. 1: subcc %o4, (1 << 5), %o4
  223. stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
  224. membar #Sync
  225. bne,pt %icc, 1b
  226. nop
  227. retl /* I-cache flush never needed on Cheetah, see callers. */
  228. nop
  229. #endif /* DCACHE_ALIASING_POSSIBLE */
  230. cheetah_patch_one:
  231. 1: lduw [%o1], %g1
  232. stw %g1, [%o0]
  233. flush %o0
  234. subcc %o2, 1, %o2
  235. add %o1, 4, %o1
  236. bne,pt %icc, 1b
  237. add %o0, 4, %o0
  238. retl
  239. nop
  240. .globl cheetah_patch_cachetlbops
  241. cheetah_patch_cachetlbops:
  242. save %sp, -128, %sp
  243. sethi %hi(__flush_tlb_mm), %o0
  244. or %o0, %lo(__flush_tlb_mm), %o0
  245. sethi %hi(__cheetah_flush_tlb_mm), %o1
  246. or %o1, %lo(__cheetah_flush_tlb_mm), %o1
  247. call cheetah_patch_one
  248. mov 18, %o2
  249. sethi %hi(__flush_tlb_pending), %o0
  250. or %o0, %lo(__flush_tlb_pending), %o0
  251. sethi %hi(__cheetah_flush_tlb_pending), %o1
  252. or %o1, %lo(__cheetah_flush_tlb_pending), %o1
  253. call cheetah_patch_one
  254. mov 26, %o2
  255. #ifdef DCACHE_ALIASING_POSSIBLE
  256. sethi %hi(__flush_dcache_page), %o0
  257. or %o0, %lo(__flush_dcache_page), %o0
  258. sethi %hi(__cheetah_flush_dcache_page), %o1
  259. or %o1, %lo(__cheetah_flush_dcache_page), %o1
  260. call cheetah_patch_one
  261. mov 11, %o2
  262. #endif /* DCACHE_ALIASING_POSSIBLE */
  263. ret
  264. restore
  265. #ifdef CONFIG_SMP
  266. /* These are all called by the slaves of a cross call, at
  267. * trap level 1, with interrupts fully disabled.
  268. *
  269. * Register usage:
  270. * %g5 mm->context (all tlb flushes)
  271. * %g1 address arg 1 (tlb page and range flushes)
  272. * %g7 address arg 2 (tlb range flush only)
  273. *
  274. * %g6 ivector table, don't touch
  275. * %g2 scratch 1
  276. * %g3 scratch 2
  277. * %g4 scratch 3
  278. *
  279. * TODO: Make xcall TLB range flushes use the tricks above... -DaveM
  280. */
  281. .align 32
  282. .globl xcall_flush_tlb_mm
  283. xcall_flush_tlb_mm:
  284. mov PRIMARY_CONTEXT, %g2
  285. ldxa [%g2] ASI_DMMU, %g3
  286. srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
  287. sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
  288. or %g5, %g4, %g5 /* Preserve nucleus page size fields */
  289. stxa %g5, [%g2] ASI_DMMU
  290. mov 0x40, %g4
  291. stxa %g0, [%g4] ASI_DMMU_DEMAP
  292. stxa %g0, [%g4] ASI_IMMU_DEMAP
  293. stxa %g3, [%g2] ASI_DMMU
  294. retry
  295. .globl xcall_flush_tlb_pending
  296. xcall_flush_tlb_pending:
  297. /* %g5=context, %g1=nr, %g7=vaddrs[] */
  298. sllx %g1, 3, %g1
  299. mov PRIMARY_CONTEXT, %g4
  300. ldxa [%g4] ASI_DMMU, %g2
  301. srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
  302. sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
  303. or %g5, %g4, %g5
  304. mov PRIMARY_CONTEXT, %g4
  305. stxa %g5, [%g4] ASI_DMMU
  306. 1: sub %g1, (1 << 3), %g1
  307. ldx [%g7 + %g1], %g5
  308. andcc %g5, 0x1, %g0
  309. be,pn %icc, 2f
  310. andn %g5, 0x1, %g5
  311. stxa %g0, [%g5] ASI_IMMU_DEMAP
  312. 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
  313. membar #Sync
  314. brnz,pt %g1, 1b
  315. nop
  316. stxa %g2, [%g4] ASI_DMMU
  317. retry
  318. .globl xcall_flush_tlb_kernel_range
  319. xcall_flush_tlb_kernel_range:
  320. sethi %hi(PAGE_SIZE - 1), %g2
  321. or %g2, %lo(PAGE_SIZE - 1), %g2
  322. andn %g1, %g2, %g1
  323. andn %g7, %g2, %g7
  324. sub %g7, %g1, %g3
  325. add %g2, 1, %g2
  326. sub %g3, %g2, %g3
  327. or %g1, 0x20, %g1 ! Nucleus
  328. 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
  329. stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
  330. membar #Sync
  331. brnz,pt %g3, 1b
  332. sub %g3, %g2, %g3
  333. retry
  334. nop
  335. nop
  336. /* This runs in a very controlled environment, so we do
  337. * not need to worry about BH races etc.
  338. */
  339. .globl xcall_sync_tick
  340. xcall_sync_tick:
  341. rdpr %pstate, %g2
  342. wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
  343. rdpr %pil, %g2
  344. wrpr %g0, 15, %pil
  345. sethi %hi(109f), %g7
  346. b,pt %xcc, etrap_irq
  347. 109: or %g7, %lo(109b), %g7
  348. call smp_synchronize_tick_client
  349. nop
  350. clr %l6
  351. b rtrap_xcall
  352. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  353. /* NOTE: This is SPECIAL!! We do etrap/rtrap however
  354. * we choose to deal with the "BH's run with
  355. * %pil==15" problem (described in asm/pil.h)
  356. * by just invoking rtrap directly past where
  357. * BH's are checked for.
  358. *
  359. * We do it like this because we do not want %pil==15
  360. * lockups to prevent regs being reported.
  361. */
  362. .globl xcall_report_regs
  363. xcall_report_regs:
  364. rdpr %pstate, %g2
  365. wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
  366. rdpr %pil, %g2
  367. wrpr %g0, 15, %pil
  368. sethi %hi(109f), %g7
  369. b,pt %xcc, etrap_irq
  370. 109: or %g7, %lo(109b), %g7
  371. call __show_regs
  372. add %sp, PTREGS_OFF, %o0
  373. clr %l6
  374. /* Has to be a non-v9 branch due to the large distance. */
  375. b rtrap_xcall
  376. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  377. #ifdef DCACHE_ALIASING_POSSIBLE
  378. .align 32
  379. .globl xcall_flush_dcache_page_cheetah
  380. xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
  381. sethi %hi(PAGE_SIZE), %g3
  382. 1: subcc %g3, (1 << 5), %g3
  383. stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
  384. membar #Sync
  385. bne,pt %icc, 1b
  386. nop
  387. retry
  388. nop
  389. #endif /* DCACHE_ALIASING_POSSIBLE */
  390. .globl xcall_flush_dcache_page_spitfire
  391. xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
  392. %g7 == kernel page virtual address
  393. %g5 == (page->mapping != NULL) */
  394. #ifdef DCACHE_ALIASING_POSSIBLE
  395. srlx %g1, (13 - 2), %g1 ! Form tag comparitor
  396. sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
  397. sub %g3, (1 << 5), %g3 ! D$ linesize == 32
  398. 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
  399. andcc %g2, 0x3, %g0
  400. be,pn %xcc, 2f
  401. andn %g2, 0x3, %g2
  402. cmp %g2, %g1
  403. bne,pt %xcc, 2f
  404. nop
  405. stxa %g0, [%g3] ASI_DCACHE_TAG
  406. membar #Sync
  407. 2: cmp %g3, 0
  408. bne,pt %xcc, 1b
  409. sub %g3, (1 << 5), %g3
  410. brz,pn %g5, 2f
  411. #endif /* DCACHE_ALIASING_POSSIBLE */
  412. sethi %hi(PAGE_SIZE), %g3
  413. 1: flush %g7
  414. subcc %g3, (1 << 5), %g3
  415. bne,pt %icc, 1b
  416. add %g7, (1 << 5), %g7
  417. 2: retry
  418. nop
  419. nop
  420. .data
  421. errata32_hwbug:
  422. .xword 0
  423. .text
  424. /* These two are not performance critical... */
  425. .globl xcall_flush_tlb_all_spitfire
  426. xcall_flush_tlb_all_spitfire:
  427. /* Spitfire Errata #32 workaround. */
  428. sethi %hi(errata32_hwbug), %g4
  429. stx %g0, [%g4 + %lo(errata32_hwbug)]
  430. clr %g2
  431. clr %g3
  432. 1: ldxa [%g3] ASI_DTLB_DATA_ACCESS, %g4
  433. and %g4, _PAGE_L, %g5
  434. brnz,pn %g5, 2f
  435. mov TLB_TAG_ACCESS, %g7
  436. stxa %g0, [%g7] ASI_DMMU
  437. membar #Sync
  438. stxa %g0, [%g3] ASI_DTLB_DATA_ACCESS
  439. membar #Sync
  440. /* Spitfire Errata #32 workaround. */
  441. sethi %hi(errata32_hwbug), %g4
  442. stx %g0, [%g4 + %lo(errata32_hwbug)]
  443. 2: ldxa [%g3] ASI_ITLB_DATA_ACCESS, %g4
  444. and %g4, _PAGE_L, %g5
  445. brnz,pn %g5, 2f
  446. mov TLB_TAG_ACCESS, %g7
  447. stxa %g0, [%g7] ASI_IMMU
  448. membar #Sync
  449. stxa %g0, [%g3] ASI_ITLB_DATA_ACCESS
  450. membar #Sync
  451. /* Spitfire Errata #32 workaround. */
  452. sethi %hi(errata32_hwbug), %g4
  453. stx %g0, [%g4 + %lo(errata32_hwbug)]
  454. 2: add %g2, 1, %g2
  455. cmp %g2, SPITFIRE_HIGHEST_LOCKED_TLBENT
  456. ble,pt %icc, 1b
  457. sll %g2, 3, %g3
  458. flush %g6
  459. retry
  460. .globl xcall_flush_tlb_all_cheetah
  461. xcall_flush_tlb_all_cheetah:
  462. mov 0x80, %g2
  463. stxa %g0, [%g2] ASI_DMMU_DEMAP
  464. stxa %g0, [%g2] ASI_IMMU_DEMAP
  465. retry
  466. /* These just get rescheduled to PIL vectors. */
  467. .globl xcall_call_function
  468. xcall_call_function:
  469. wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
  470. retry
  471. .globl xcall_receive_signal
  472. xcall_receive_signal:
  473. wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
  474. retry
  475. .globl xcall_capture
  476. xcall_capture:
  477. wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
  478. retry
  479. #endif /* CONFIG_SMP */