ultra.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 scratch 1
  275. * %g2 scratch 2
  276. * %g3 scratch 3
  277. * %g4 scratch 4
  278. */
  279. .align 32
  280. .globl xcall_flush_tlb_mm
  281. xcall_flush_tlb_mm:
  282. mov PRIMARY_CONTEXT, %g2
  283. ldxa [%g2] ASI_DMMU, %g3
  284. srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
  285. sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
  286. or %g5, %g4, %g5 /* Preserve nucleus page size fields */
  287. stxa %g5, [%g2] ASI_DMMU
  288. mov 0x40, %g4
  289. stxa %g0, [%g4] ASI_DMMU_DEMAP
  290. stxa %g0, [%g4] ASI_IMMU_DEMAP
  291. stxa %g3, [%g2] ASI_DMMU
  292. retry
  293. .globl xcall_flush_tlb_pending
  294. xcall_flush_tlb_pending:
  295. /* %g5=context, %g1=nr, %g7=vaddrs[] */
  296. sllx %g1, 3, %g1
  297. mov PRIMARY_CONTEXT, %g4
  298. ldxa [%g4] ASI_DMMU, %g2
  299. srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
  300. sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
  301. or %g5, %g4, %g5
  302. mov PRIMARY_CONTEXT, %g4
  303. stxa %g5, [%g4] ASI_DMMU
  304. 1: sub %g1, (1 << 3), %g1
  305. ldx [%g7 + %g1], %g5
  306. andcc %g5, 0x1, %g0
  307. be,pn %icc, 2f
  308. andn %g5, 0x1, %g5
  309. stxa %g0, [%g5] ASI_IMMU_DEMAP
  310. 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
  311. membar #Sync
  312. brnz,pt %g1, 1b
  313. nop
  314. stxa %g2, [%g4] ASI_DMMU
  315. retry
  316. .globl xcall_flush_tlb_kernel_range
  317. xcall_flush_tlb_kernel_range:
  318. sethi %hi(PAGE_SIZE - 1), %g2
  319. or %g2, %lo(PAGE_SIZE - 1), %g2
  320. andn %g1, %g2, %g1
  321. andn %g7, %g2, %g7
  322. sub %g7, %g1, %g3
  323. add %g2, 1, %g2
  324. sub %g3, %g2, %g3
  325. or %g1, 0x20, %g1 ! Nucleus
  326. 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
  327. stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
  328. membar #Sync
  329. brnz,pt %g3, 1b
  330. sub %g3, %g2, %g3
  331. retry
  332. nop
  333. nop
  334. /* This runs in a very controlled environment, so we do
  335. * not need to worry about BH races etc.
  336. */
  337. .globl xcall_sync_tick
  338. xcall_sync_tick:
  339. rdpr %pstate, %g2
  340. wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
  341. rdpr %pil, %g2
  342. wrpr %g0, 15, %pil
  343. sethi %hi(109f), %g7
  344. b,pt %xcc, etrap_irq
  345. 109: or %g7, %lo(109b), %g7
  346. call smp_synchronize_tick_client
  347. nop
  348. clr %l6
  349. b rtrap_xcall
  350. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  351. /* NOTE: This is SPECIAL!! We do etrap/rtrap however
  352. * we choose to deal with the "BH's run with
  353. * %pil==15" problem (described in asm/pil.h)
  354. * by just invoking rtrap directly past where
  355. * BH's are checked for.
  356. *
  357. * We do it like this because we do not want %pil==15
  358. * lockups to prevent regs being reported.
  359. */
  360. .globl xcall_report_regs
  361. xcall_report_regs:
  362. rdpr %pstate, %g2
  363. wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
  364. rdpr %pil, %g2
  365. wrpr %g0, 15, %pil
  366. sethi %hi(109f), %g7
  367. b,pt %xcc, etrap_irq
  368. 109: or %g7, %lo(109b), %g7
  369. call __show_regs
  370. add %sp, PTREGS_OFF, %o0
  371. clr %l6
  372. /* Has to be a non-v9 branch due to the large distance. */
  373. b rtrap_xcall
  374. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
  375. #ifdef DCACHE_ALIASING_POSSIBLE
  376. .align 32
  377. .globl xcall_flush_dcache_page_cheetah
  378. xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
  379. sethi %hi(PAGE_SIZE), %g3
  380. 1: subcc %g3, (1 << 5), %g3
  381. stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
  382. membar #Sync
  383. bne,pt %icc, 1b
  384. nop
  385. retry
  386. nop
  387. #endif /* DCACHE_ALIASING_POSSIBLE */
  388. .globl xcall_flush_dcache_page_spitfire
  389. xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
  390. %g7 == kernel page virtual address
  391. %g5 == (page->mapping != NULL) */
  392. #ifdef DCACHE_ALIASING_POSSIBLE
  393. srlx %g1, (13 - 2), %g1 ! Form tag comparitor
  394. sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
  395. sub %g3, (1 << 5), %g3 ! D$ linesize == 32
  396. 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
  397. andcc %g2, 0x3, %g0
  398. be,pn %xcc, 2f
  399. andn %g2, 0x3, %g2
  400. cmp %g2, %g1
  401. bne,pt %xcc, 2f
  402. nop
  403. stxa %g0, [%g3] ASI_DCACHE_TAG
  404. membar #Sync
  405. 2: cmp %g3, 0
  406. bne,pt %xcc, 1b
  407. sub %g3, (1 << 5), %g3
  408. brz,pn %g5, 2f
  409. #endif /* DCACHE_ALIASING_POSSIBLE */
  410. sethi %hi(PAGE_SIZE), %g3
  411. 1: flush %g7
  412. subcc %g3, (1 << 5), %g3
  413. bne,pt %icc, 1b
  414. add %g7, (1 << 5), %g7
  415. 2: retry
  416. nop
  417. nop
  418. /* These just get rescheduled to PIL vectors. */
  419. .globl xcall_call_function
  420. xcall_call_function:
  421. wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
  422. retry
  423. .globl xcall_receive_signal
  424. xcall_receive_signal:
  425. wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
  426. retry
  427. .globl xcall_capture
  428. xcall_capture:
  429. wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
  430. retry
  431. #endif /* CONFIG_SMP */