trampoline.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /* $Id: trampoline.S,v 1.26 2002/02/09 19:49:30 davem Exp $
  2. * trampoline.S: Jump start slave processors on sparc64.
  3. *
  4. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <asm/head.h>
  7. #include <asm/asi.h>
  8. #include <asm/lsu.h>
  9. #include <asm/dcr.h>
  10. #include <asm/dcu.h>
  11. #include <asm/pstate.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/spitfire.h>
  15. #include <asm/processor.h>
  16. #include <asm/thread_info.h>
  17. #include <asm/mmu.h>
  18. #include <asm/hypervisor.h>
  19. #include <asm/cpudata.h>
  20. .data
  21. .align 8
  22. call_method:
  23. .asciz "call-method"
  24. .align 8
  25. itlb_load:
  26. .asciz "SUNW,itlb-load"
  27. .align 8
  28. dtlb_load:
  29. .asciz "SUNW,dtlb-load"
  30. /* XXX __cpuinit this thing XXX */
  31. #define TRAMP_STACK_SIZE 1024
  32. .align 16
  33. tramp_stack:
  34. .skip TRAMP_STACK_SIZE
  35. .text
  36. .align 8
  37. .globl sparc64_cpu_startup, sparc64_cpu_startup_end
  38. sparc64_cpu_startup:
  39. BRANCH_IF_SUN4V(g1, niagara_startup)
  40. BRANCH_IF_CHEETAH_BASE(g1, g5, cheetah_startup)
  41. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1, g5, cheetah_plus_startup)
  42. ba,pt %xcc, spitfire_startup
  43. nop
  44. cheetah_plus_startup:
  45. /* Preserve OBP chosen DCU and DCR register settings. */
  46. ba,pt %xcc, cheetah_generic_startup
  47. nop
  48. cheetah_startup:
  49. mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
  50. wr %g1, %asr18
  51. sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
  52. or %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
  53. sllx %g5, 32, %g5
  54. or %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
  55. stxa %g5, [%g0] ASI_DCU_CONTROL_REG
  56. membar #Sync
  57. /* fallthru */
  58. cheetah_generic_startup:
  59. mov TSB_EXTENSION_P, %g3
  60. stxa %g0, [%g3] ASI_DMMU
  61. stxa %g0, [%g3] ASI_IMMU
  62. membar #Sync
  63. mov TSB_EXTENSION_S, %g3
  64. stxa %g0, [%g3] ASI_DMMU
  65. membar #Sync
  66. mov TSB_EXTENSION_N, %g3
  67. stxa %g0, [%g3] ASI_DMMU
  68. stxa %g0, [%g3] ASI_IMMU
  69. membar #Sync
  70. /* fallthru */
  71. niagara_startup:
  72. /* Disable STICK_INT interrupts. */
  73. sethi %hi(0x80000000), %g5
  74. sllx %g5, 32, %g5
  75. wr %g5, %asr25
  76. ba,pt %xcc, startup_continue
  77. nop
  78. spitfire_startup:
  79. mov (LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
  80. stxa %g1, [%g0] ASI_LSU_CONTROL
  81. membar #Sync
  82. startup_continue:
  83. sethi %hi(0x80000000), %g2
  84. sllx %g2, 32, %g2
  85. wr %g2, 0, %tick_cmpr
  86. mov %o0, %l0
  87. BRANCH_IF_SUN4V(g1, niagara_lock_tlb)
  88. /* Call OBP by hand to lock KERNBASE into i/d tlbs.
  89. * We lock 2 consequetive entries if we are 'bigkernel'.
  90. */
  91. sethi %hi(prom_entry_lock), %g2
  92. 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
  93. membar #StoreLoad | #StoreStore
  94. brnz,pn %g1, 1b
  95. nop
  96. sethi %hi(p1275buf), %g2
  97. or %g2, %lo(p1275buf), %g2
  98. ldx [%g2 + 0x10], %l2
  99. add %l2, -(192 + 128), %sp
  100. flushw
  101. sethi %hi(call_method), %g2
  102. or %g2, %lo(call_method), %g2
  103. stx %g2, [%sp + 2047 + 128 + 0x00]
  104. mov 5, %g2
  105. stx %g2, [%sp + 2047 + 128 + 0x08]
  106. mov 1, %g2
  107. stx %g2, [%sp + 2047 + 128 + 0x10]
  108. sethi %hi(itlb_load), %g2
  109. or %g2, %lo(itlb_load), %g2
  110. stx %g2, [%sp + 2047 + 128 + 0x18]
  111. sethi %hi(prom_mmu_ihandle_cache), %g2
  112. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  113. stx %g2, [%sp + 2047 + 128 + 0x20]
  114. sethi %hi(KERNBASE), %g2
  115. stx %g2, [%sp + 2047 + 128 + 0x28]
  116. sethi %hi(kern_locked_tte_data), %g2
  117. ldx [%g2 + %lo(kern_locked_tte_data)], %g2
  118. stx %g2, [%sp + 2047 + 128 + 0x30]
  119. mov 15, %g2
  120. BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
  121. mov 63, %g2
  122. 1:
  123. stx %g2, [%sp + 2047 + 128 + 0x38]
  124. sethi %hi(p1275buf), %g2
  125. or %g2, %lo(p1275buf), %g2
  126. ldx [%g2 + 0x08], %o1
  127. call %o1
  128. add %sp, (2047 + 128), %o0
  129. sethi %hi(bigkernel), %g2
  130. lduw [%g2 + %lo(bigkernel)], %g2
  131. brz,pt %g2, do_dtlb
  132. nop
  133. sethi %hi(call_method), %g2
  134. or %g2, %lo(call_method), %g2
  135. stx %g2, [%sp + 2047 + 128 + 0x00]
  136. mov 5, %g2
  137. stx %g2, [%sp + 2047 + 128 + 0x08]
  138. mov 1, %g2
  139. stx %g2, [%sp + 2047 + 128 + 0x10]
  140. sethi %hi(itlb_load), %g2
  141. or %g2, %lo(itlb_load), %g2
  142. stx %g2, [%sp + 2047 + 128 + 0x18]
  143. sethi %hi(prom_mmu_ihandle_cache), %g2
  144. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  145. stx %g2, [%sp + 2047 + 128 + 0x20]
  146. sethi %hi(KERNBASE + 0x400000), %g2
  147. stx %g2, [%sp + 2047 + 128 + 0x28]
  148. sethi %hi(kern_locked_tte_data), %g2
  149. ldx [%g2 + %lo(kern_locked_tte_data)], %g2
  150. sethi %hi(0x400000), %g1
  151. add %g2, %g1, %g2
  152. stx %g2, [%sp + 2047 + 128 + 0x30]
  153. mov 14, %g2
  154. BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
  155. mov 62, %g2
  156. 1:
  157. stx %g2, [%sp + 2047 + 128 + 0x38]
  158. sethi %hi(p1275buf), %g2
  159. or %g2, %lo(p1275buf), %g2
  160. ldx [%g2 + 0x08], %o1
  161. call %o1
  162. add %sp, (2047 + 128), %o0
  163. do_dtlb:
  164. sethi %hi(call_method), %g2
  165. or %g2, %lo(call_method), %g2
  166. stx %g2, [%sp + 2047 + 128 + 0x00]
  167. mov 5, %g2
  168. stx %g2, [%sp + 2047 + 128 + 0x08]
  169. mov 1, %g2
  170. stx %g2, [%sp + 2047 + 128 + 0x10]
  171. sethi %hi(dtlb_load), %g2
  172. or %g2, %lo(dtlb_load), %g2
  173. stx %g2, [%sp + 2047 + 128 + 0x18]
  174. sethi %hi(prom_mmu_ihandle_cache), %g2
  175. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  176. stx %g2, [%sp + 2047 + 128 + 0x20]
  177. sethi %hi(KERNBASE), %g2
  178. stx %g2, [%sp + 2047 + 128 + 0x28]
  179. sethi %hi(kern_locked_tte_data), %g2
  180. ldx [%g2 + %lo(kern_locked_tte_data)], %g2
  181. stx %g2, [%sp + 2047 + 128 + 0x30]
  182. mov 15, %g2
  183. BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
  184. mov 63, %g2
  185. 1:
  186. stx %g2, [%sp + 2047 + 128 + 0x38]
  187. sethi %hi(p1275buf), %g2
  188. or %g2, %lo(p1275buf), %g2
  189. ldx [%g2 + 0x08], %o1
  190. call %o1
  191. add %sp, (2047 + 128), %o0
  192. sethi %hi(bigkernel), %g2
  193. lduw [%g2 + %lo(bigkernel)], %g2
  194. brz,pt %g2, do_unlock
  195. nop
  196. sethi %hi(call_method), %g2
  197. or %g2, %lo(call_method), %g2
  198. stx %g2, [%sp + 2047 + 128 + 0x00]
  199. mov 5, %g2
  200. stx %g2, [%sp + 2047 + 128 + 0x08]
  201. mov 1, %g2
  202. stx %g2, [%sp + 2047 + 128 + 0x10]
  203. sethi %hi(dtlb_load), %g2
  204. or %g2, %lo(dtlb_load), %g2
  205. stx %g2, [%sp + 2047 + 128 + 0x18]
  206. sethi %hi(prom_mmu_ihandle_cache), %g2
  207. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  208. stx %g2, [%sp + 2047 + 128 + 0x20]
  209. sethi %hi(KERNBASE + 0x400000), %g2
  210. stx %g2, [%sp + 2047 + 128 + 0x28]
  211. sethi %hi(kern_locked_tte_data), %g2
  212. ldx [%g2 + %lo(kern_locked_tte_data)], %g2
  213. sethi %hi(0x400000), %g1
  214. add %g2, %g1, %g2
  215. stx %g2, [%sp + 2047 + 128 + 0x30]
  216. mov 14, %g2
  217. BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
  218. mov 62, %g2
  219. 1:
  220. stx %g2, [%sp + 2047 + 128 + 0x38]
  221. sethi %hi(p1275buf), %g2
  222. or %g2, %lo(p1275buf), %g2
  223. ldx [%g2 + 0x08], %o1
  224. call %o1
  225. add %sp, (2047 + 128), %o0
  226. do_unlock:
  227. sethi %hi(prom_entry_lock), %g2
  228. stb %g0, [%g2 + %lo(prom_entry_lock)]
  229. membar #StoreStore | #StoreLoad
  230. ba,pt %xcc, after_lock_tlb
  231. nop
  232. niagara_lock_tlb:
  233. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  234. sethi %hi(KERNBASE), %o0
  235. clr %o1
  236. sethi %hi(kern_locked_tte_data), %o2
  237. ldx [%o2 + %lo(kern_locked_tte_data)], %o2
  238. mov HV_MMU_IMMU, %o3
  239. ta HV_FAST_TRAP
  240. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  241. sethi %hi(KERNBASE), %o0
  242. clr %o1
  243. sethi %hi(kern_locked_tte_data), %o2
  244. ldx [%o2 + %lo(kern_locked_tte_data)], %o2
  245. mov HV_MMU_DMMU, %o3
  246. ta HV_FAST_TRAP
  247. sethi %hi(bigkernel), %g2
  248. lduw [%g2 + %lo(bigkernel)], %g2
  249. brz,pt %g2, after_lock_tlb
  250. nop
  251. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  252. sethi %hi(KERNBASE + 0x400000), %o0
  253. clr %o1
  254. sethi %hi(kern_locked_tte_data), %o2
  255. ldx [%o2 + %lo(kern_locked_tte_data)], %o2
  256. sethi %hi(0x400000), %o3
  257. add %o2, %o3, %o2
  258. mov HV_MMU_IMMU, %o3
  259. ta HV_FAST_TRAP
  260. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  261. sethi %hi(KERNBASE + 0x400000), %o0
  262. clr %o1
  263. sethi %hi(kern_locked_tte_data), %o2
  264. ldx [%o2 + %lo(kern_locked_tte_data)], %o2
  265. sethi %hi(0x400000), %o3
  266. add %o2, %o3, %o2
  267. mov HV_MMU_DMMU, %o3
  268. ta HV_FAST_TRAP
  269. after_lock_tlb:
  270. wrpr %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
  271. wr %g0, 0, %fprs
  272. wr %g0, ASI_P, %asi
  273. mov PRIMARY_CONTEXT, %g7
  274. 661: stxa %g0, [%g7] ASI_DMMU
  275. .section .sun4v_1insn_patch, "ax"
  276. .word 661b
  277. stxa %g0, [%g7] ASI_MMU
  278. .previous
  279. membar #Sync
  280. mov SECONDARY_CONTEXT, %g7
  281. 661: stxa %g0, [%g7] ASI_DMMU
  282. .section .sun4v_1insn_patch, "ax"
  283. .word 661b
  284. stxa %g0, [%g7] ASI_MMU
  285. .previous
  286. membar #Sync
  287. /* Everything we do here, until we properly take over the
  288. * trap table, must be done with extreme care. We cannot
  289. * make any references to %g6 (current thread pointer),
  290. * %g4 (current task pointer), or %g5 (base of current cpu's
  291. * per-cpu area) until we properly take over the trap table
  292. * from the firmware and hypervisor.
  293. *
  294. * Get onto temporary stack which is in the locked kernel image.
  295. */
  296. sethi %hi(tramp_stack), %g1
  297. or %g1, %lo(tramp_stack), %g1
  298. add %g1, TRAMP_STACK_SIZE, %g1
  299. sub %g1, STACKFRAME_SZ + STACK_BIAS, %sp
  300. mov 0, %fp
  301. /* Put garbage in these registers to trap any access to them. */
  302. set 0xdeadbeef, %g4
  303. set 0xdeadbeef, %g5
  304. set 0xdeadbeef, %g6
  305. call init_irqwork_curcpu
  306. nop
  307. sethi %hi(tlb_type), %g3
  308. lduw [%g3 + %lo(tlb_type)], %g2
  309. cmp %g2, 3
  310. bne,pt %icc, 1f
  311. nop
  312. call hard_smp_processor_id
  313. nop
  314. mov %o0, %o1
  315. mov 0, %o0
  316. mov 0, %o2
  317. call sun4v_init_mondo_queues
  318. mov 1, %o3
  319. 1: call init_cur_cpu_trap
  320. ldx [%l0], %o0
  321. /* Start using proper page size encodings in ctx register. */
  322. sethi %hi(sparc64_kern_pri_context), %g3
  323. ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
  324. mov PRIMARY_CONTEXT, %g1
  325. 661: stxa %g2, [%g1] ASI_DMMU
  326. .section .sun4v_1insn_patch, "ax"
  327. .word 661b
  328. stxa %g2, [%g1] ASI_MMU
  329. .previous
  330. membar #Sync
  331. wrpr %g0, 0, %wstate
  332. /* As a hack, put &init_thread_union into %g6.
  333. * prom_world() loads from here to restore the %asi
  334. * register.
  335. */
  336. sethi %hi(init_thread_union), %g6
  337. or %g6, %lo(init_thread_union), %g6
  338. sethi %hi(is_sun4v), %o0
  339. lduw [%o0 + %lo(is_sun4v)], %o0
  340. brz,pt %o0, 1f
  341. nop
  342. TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
  343. add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  344. stxa %g2, [%g0] ASI_SCRATCHPAD
  345. /* Compute physical address:
  346. *
  347. * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
  348. */
  349. sethi %hi(KERNBASE), %g3
  350. sub %g2, %g3, %g2
  351. sethi %hi(kern_base), %g3
  352. ldx [%g3 + %lo(kern_base)], %g3
  353. add %g2, %g3, %o1
  354. call prom_set_trap_table_sun4v
  355. sethi %hi(sparc64_ttable_tl0), %o0
  356. ba,pt %xcc, 2f
  357. nop
  358. 1: call prom_set_trap_table
  359. sethi %hi(sparc64_ttable_tl0), %o0
  360. 2: ldx [%l0], %g6
  361. ldx [%g6 + TI_TASK], %g4
  362. mov 1, %g5
  363. sllx %g5, THREAD_SHIFT, %g5
  364. sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
  365. add %g6, %g5, %sp
  366. mov 0, %fp
  367. rdpr %pstate, %o1
  368. or %o1, PSTATE_IE, %o1
  369. wrpr %o1, 0, %pstate
  370. call smp_callin
  371. nop
  372. call cpu_idle
  373. mov 0, %o0
  374. call cpu_panic
  375. nop
  376. 1: b,a,pt %xcc, 1b
  377. .align 8
  378. sparc64_cpu_startup_end: