trampoline_64.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  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. #define TRAMP_STACK_SIZE 1024
  31. .align 16
  32. tramp_stack:
  33. .skip TRAMP_STACK_SIZE
  34. .align 8
  35. .globl sparc64_cpu_startup, sparc64_cpu_startup_end
  36. sparc64_cpu_startup:
  37. BRANCH_IF_SUN4V(g1, niagara_startup)
  38. BRANCH_IF_CHEETAH_BASE(g1, g5, cheetah_startup)
  39. BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1, g5, cheetah_plus_startup)
  40. ba,pt %xcc, spitfire_startup
  41. nop
  42. cheetah_plus_startup:
  43. /* Preserve OBP chosen DCU and DCR register settings. */
  44. ba,pt %xcc, cheetah_generic_startup
  45. nop
  46. cheetah_startup:
  47. mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
  48. wr %g1, %asr18
  49. sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
  50. or %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
  51. sllx %g5, 32, %g5
  52. or %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
  53. stxa %g5, [%g0] ASI_DCU_CONTROL_REG
  54. membar #Sync
  55. /* fallthru */
  56. cheetah_generic_startup:
  57. mov TSB_EXTENSION_P, %g3
  58. stxa %g0, [%g3] ASI_DMMU
  59. stxa %g0, [%g3] ASI_IMMU
  60. membar #Sync
  61. mov TSB_EXTENSION_S, %g3
  62. stxa %g0, [%g3] ASI_DMMU
  63. membar #Sync
  64. mov TSB_EXTENSION_N, %g3
  65. stxa %g0, [%g3] ASI_DMMU
  66. stxa %g0, [%g3] ASI_IMMU
  67. membar #Sync
  68. /* fallthru */
  69. niagara_startup:
  70. /* Disable STICK_INT interrupts. */
  71. sethi %hi(0x80000000), %g5
  72. sllx %g5, 32, %g5
  73. wr %g5, %asr25
  74. ba,pt %xcc, startup_continue
  75. nop
  76. spitfire_startup:
  77. mov (LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
  78. stxa %g1, [%g0] ASI_LSU_CONTROL
  79. membar #Sync
  80. startup_continue:
  81. mov %o0, %l0
  82. BRANCH_IF_SUN4V(g1, niagara_lock_tlb)
  83. sethi %hi(0x80000000), %g2
  84. sllx %g2, 32, %g2
  85. wr %g2, 0, %tick_cmpr
  86. /* Call OBP by hand to lock KERNBASE into i/d tlbs.
  87. * We lock 'num_kernel_image_mappings' consequetive entries.
  88. */
  89. sethi %hi(prom_entry_lock), %g2
  90. 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
  91. brnz,pn %g1, 1b
  92. nop
  93. /* Get onto temporary stack which will be in the locked
  94. * kernel image.
  95. */
  96. sethi %hi(tramp_stack), %g1
  97. or %g1, %lo(tramp_stack), %g1
  98. add %g1, TRAMP_STACK_SIZE, %g1
  99. sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
  100. flushw
  101. /* Setup the loop variables:
  102. * %l3: VADDR base
  103. * %l4: TTE base
  104. * %l5: Loop iterator, iterates from 0 to 'num_kernel_image_mappings'
  105. * %l6: Number of TTE entries to map
  106. * %l7: Highest TTE entry number, we count down
  107. */
  108. sethi %hi(KERNBASE), %l3
  109. sethi %hi(kern_locked_tte_data), %l4
  110. ldx [%l4 + %lo(kern_locked_tte_data)], %l4
  111. clr %l5
  112. sethi %hi(num_kernel_image_mappings), %l6
  113. lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
  114. mov 15, %l7
  115. BRANCH_IF_ANY_CHEETAH(g1,g5,2f)
  116. mov 63, %l7
  117. 2:
  118. 3:
  119. /* Lock into I-MMU */
  120. sethi %hi(call_method), %g2
  121. or %g2, %lo(call_method), %g2
  122. stx %g2, [%sp + 2047 + 128 + 0x00]
  123. mov 5, %g2
  124. stx %g2, [%sp + 2047 + 128 + 0x08]
  125. mov 1, %g2
  126. stx %g2, [%sp + 2047 + 128 + 0x10]
  127. sethi %hi(itlb_load), %g2
  128. or %g2, %lo(itlb_load), %g2
  129. stx %g2, [%sp + 2047 + 128 + 0x18]
  130. sethi %hi(prom_mmu_ihandle_cache), %g2
  131. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  132. stx %g2, [%sp + 2047 + 128 + 0x20]
  133. /* Each TTE maps 4MB, convert index to offset. */
  134. sllx %l5, 22, %g1
  135. add %l3, %g1, %g2
  136. stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
  137. add %l4, %g1, %g2
  138. stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
  139. /* TTE index is highest minus loop index. */
  140. sub %l7, %l5, %g2
  141. stx %g2, [%sp + 2047 + 128 + 0x38]
  142. sethi %hi(p1275buf), %g2
  143. or %g2, %lo(p1275buf), %g2
  144. ldx [%g2 + 0x08], %o1
  145. call %o1
  146. add %sp, (2047 + 128), %o0
  147. /* Lock into D-MMU */
  148. sethi %hi(call_method), %g2
  149. or %g2, %lo(call_method), %g2
  150. stx %g2, [%sp + 2047 + 128 + 0x00]
  151. mov 5, %g2
  152. stx %g2, [%sp + 2047 + 128 + 0x08]
  153. mov 1, %g2
  154. stx %g2, [%sp + 2047 + 128 + 0x10]
  155. sethi %hi(dtlb_load), %g2
  156. or %g2, %lo(dtlb_load), %g2
  157. stx %g2, [%sp + 2047 + 128 + 0x18]
  158. sethi %hi(prom_mmu_ihandle_cache), %g2
  159. lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
  160. stx %g2, [%sp + 2047 + 128 + 0x20]
  161. /* Each TTE maps 4MB, convert index to offset. */
  162. sllx %l5, 22, %g1
  163. add %l3, %g1, %g2
  164. stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
  165. add %l4, %g1, %g2
  166. stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
  167. /* TTE index is highest minus loop index. */
  168. sub %l7, %l5, %g2
  169. stx %g2, [%sp + 2047 + 128 + 0x38]
  170. sethi %hi(p1275buf), %g2
  171. or %g2, %lo(p1275buf), %g2
  172. ldx [%g2 + 0x08], %o1
  173. call %o1
  174. add %sp, (2047 + 128), %o0
  175. add %l5, 1, %l5
  176. cmp %l5, %l6
  177. bne,pt %xcc, 3b
  178. nop
  179. sethi %hi(prom_entry_lock), %g2
  180. stb %g0, [%g2 + %lo(prom_entry_lock)]
  181. ba,pt %xcc, after_lock_tlb
  182. nop
  183. niagara_lock_tlb:
  184. sethi %hi(KERNBASE), %l3
  185. sethi %hi(kern_locked_tte_data), %l4
  186. ldx [%l4 + %lo(kern_locked_tte_data)], %l4
  187. clr %l5
  188. sethi %hi(num_kernel_image_mappings), %l6
  189. lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
  190. 1:
  191. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  192. sllx %l5, 22, %g2
  193. add %l3, %g2, %o0
  194. clr %o1
  195. add %l4, %g2, %o2
  196. mov HV_MMU_IMMU, %o3
  197. ta HV_FAST_TRAP
  198. mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
  199. sllx %l5, 22, %g2
  200. add %l3, %g2, %o0
  201. clr %o1
  202. add %l4, %g2, %o2
  203. mov HV_MMU_DMMU, %o3
  204. ta HV_FAST_TRAP
  205. add %l5, 1, %l5
  206. cmp %l5, %l6
  207. bne,pt %xcc, 1b
  208. nop
  209. after_lock_tlb:
  210. wrpr %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
  211. wr %g0, 0, %fprs
  212. wr %g0, ASI_P, %asi
  213. mov PRIMARY_CONTEXT, %g7
  214. 661: stxa %g0, [%g7] ASI_DMMU
  215. .section .sun4v_1insn_patch, "ax"
  216. .word 661b
  217. stxa %g0, [%g7] ASI_MMU
  218. .previous
  219. membar #Sync
  220. mov SECONDARY_CONTEXT, %g7
  221. 661: stxa %g0, [%g7] ASI_DMMU
  222. .section .sun4v_1insn_patch, "ax"
  223. .word 661b
  224. stxa %g0, [%g7] ASI_MMU
  225. .previous
  226. membar #Sync
  227. /* Everything we do here, until we properly take over the
  228. * trap table, must be done with extreme care. We cannot
  229. * make any references to %g6 (current thread pointer),
  230. * %g4 (current task pointer), or %g5 (base of current cpu's
  231. * per-cpu area) until we properly take over the trap table
  232. * from the firmware and hypervisor.
  233. *
  234. * Get onto temporary stack which is in the locked kernel image.
  235. */
  236. sethi %hi(tramp_stack), %g1
  237. or %g1, %lo(tramp_stack), %g1
  238. add %g1, TRAMP_STACK_SIZE, %g1
  239. sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
  240. mov 0, %fp
  241. /* Put garbage in these registers to trap any access to them. */
  242. set 0xdeadbeef, %g4
  243. set 0xdeadbeef, %g5
  244. set 0xdeadbeef, %g6
  245. call init_irqwork_curcpu
  246. nop
  247. sethi %hi(tlb_type), %g3
  248. lduw [%g3 + %lo(tlb_type)], %g2
  249. cmp %g2, 3
  250. bne,pt %icc, 1f
  251. nop
  252. call hard_smp_processor_id
  253. nop
  254. call sun4v_register_mondo_queues
  255. nop
  256. 1: call init_cur_cpu_trap
  257. ldx [%l0], %o0
  258. /* Start using proper page size encodings in ctx register. */
  259. sethi %hi(sparc64_kern_pri_context), %g3
  260. ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
  261. mov PRIMARY_CONTEXT, %g1
  262. 661: stxa %g2, [%g1] ASI_DMMU
  263. .section .sun4v_1insn_patch, "ax"
  264. .word 661b
  265. stxa %g2, [%g1] ASI_MMU
  266. .previous
  267. membar #Sync
  268. wrpr %g0, 0, %wstate
  269. sethi %hi(prom_entry_lock), %g2
  270. 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
  271. brnz,pn %g1, 1b
  272. nop
  273. /* As a hack, put &init_thread_union into %g6.
  274. * prom_world() loads from here to restore the %asi
  275. * register.
  276. */
  277. sethi %hi(init_thread_union), %g6
  278. or %g6, %lo(init_thread_union), %g6
  279. sethi %hi(is_sun4v), %o0
  280. lduw [%o0 + %lo(is_sun4v)], %o0
  281. brz,pt %o0, 2f
  282. nop
  283. TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
  284. add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
  285. stxa %g2, [%g0] ASI_SCRATCHPAD
  286. /* Compute physical address:
  287. *
  288. * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
  289. */
  290. sethi %hi(KERNBASE), %g3
  291. sub %g2, %g3, %g2
  292. sethi %hi(kern_base), %g3
  293. ldx [%g3 + %lo(kern_base)], %g3
  294. add %g2, %g3, %o1
  295. sethi %hi(sparc64_ttable_tl0), %o0
  296. set prom_set_trap_table_name, %g2
  297. stx %g2, [%sp + 2047 + 128 + 0x00]
  298. mov 2, %g2
  299. stx %g2, [%sp + 2047 + 128 + 0x08]
  300. mov 0, %g2
  301. stx %g2, [%sp + 2047 + 128 + 0x10]
  302. stx %o0, [%sp + 2047 + 128 + 0x18]
  303. stx %o1, [%sp + 2047 + 128 + 0x20]
  304. sethi %hi(p1275buf), %g2
  305. or %g2, %lo(p1275buf), %g2
  306. ldx [%g2 + 0x08], %o1
  307. call %o1
  308. add %sp, (2047 + 128), %o0
  309. ba,pt %xcc, 3f
  310. nop
  311. 2: sethi %hi(sparc64_ttable_tl0), %o0
  312. set prom_set_trap_table_name, %g2
  313. stx %g2, [%sp + 2047 + 128 + 0x00]
  314. mov 1, %g2
  315. stx %g2, [%sp + 2047 + 128 + 0x08]
  316. mov 0, %g2
  317. stx %g2, [%sp + 2047 + 128 + 0x10]
  318. stx %o0, [%sp + 2047 + 128 + 0x18]
  319. sethi %hi(p1275buf), %g2
  320. or %g2, %lo(p1275buf), %g2
  321. ldx [%g2 + 0x08], %o1
  322. call %o1
  323. add %sp, (2047 + 128), %o0
  324. 3: sethi %hi(prom_entry_lock), %g2
  325. stb %g0, [%g2 + %lo(prom_entry_lock)]
  326. ldx [%l0], %g6
  327. ldx [%g6 + TI_TASK], %g4
  328. mov 1, %g5
  329. sllx %g5, THREAD_SHIFT, %g5
  330. sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
  331. add %g6, %g5, %sp
  332. rdpr %pstate, %o1
  333. or %o1, PSTATE_IE, %o1
  334. wrpr %o1, 0, %pstate
  335. call smp_callin
  336. nop
  337. call cpu_panic
  338. nop
  339. 1: b,a,pt %xcc, 1b
  340. .align 8
  341. sparc64_cpu_startup_end: