trampoline_64.S 9.1 KB

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