1 /* $Id: trampoline.S,v 1.26 2002/02/09 19:49:30 davem Exp $
2 * trampoline.S: Jump start slave processors on sparc64.
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7 #include <linux/init.h>
14 #include <asm/pstate.h>
16 #include <asm/pgtable.h>
17 #include <asm/spitfire.h>
18 #include <asm/processor.h>
19 #include <asm/thread_info.h>
21 #include <asm/hypervisor.h>
22 #include <asm/cpudata.h>
30 .asciz "SUNW,itlb-load"
33 .asciz "SUNW,dtlb-load"
35 /* XXX __cpuinit this thing XXX */
36 #define TRAMP_STACK_SIZE 1024
39 .skip TRAMP_STACK_SIZE
43 .globl sparc64_cpu_startup, sparc64_cpu_startup_end
45 BRANCH_IF_SUN4V(g1, niagara_startup)
46 BRANCH_IF_CHEETAH_BASE(g1, g5, cheetah_startup)
47 BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1, g5, cheetah_plus_startup)
49 ba,pt %xcc, spitfire_startup
53 /* Preserve OBP chosen DCU and DCR register settings. */
54 ba,pt %xcc, cheetah_generic_startup
58 mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
61 sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
62 or %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
64 or %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
65 stxa %g5, [%g0] ASI_DCU_CONTROL_REG
69 cheetah_generic_startup:
70 mov TSB_EXTENSION_P, %g3
71 stxa %g0, [%g3] ASI_DMMU
72 stxa %g0, [%g3] ASI_IMMU
75 mov TSB_EXTENSION_S, %g3
76 stxa %g0, [%g3] ASI_DMMU
79 mov TSB_EXTENSION_N, %g3
80 stxa %g0, [%g3] ASI_DMMU
81 stxa %g0, [%g3] ASI_IMMU
86 /* Disable STICK_INT interrupts. */
87 sethi %hi(0x80000000), %g5
91 ba,pt %xcc, startup_continue
95 mov (LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
96 stxa %g1, [%g0] ASI_LSU_CONTROL
101 BRANCH_IF_SUN4V(g1, niagara_lock_tlb)
103 sethi %hi(0x80000000), %g2
105 wr %g2, 0, %tick_cmpr
107 /* Call OBP by hand to lock KERNBASE into i/d tlbs.
108 * We lock 2 consequetive entries if we are 'bigkernel'.
110 sethi %hi(prom_entry_lock), %g2
111 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
112 membar #StoreLoad | #StoreStore
116 sethi %hi(p1275buf), %g2
117 or %g2, %lo(p1275buf), %g2
118 ldx [%g2 + 0x10], %l2
119 add %l2, -(192 + 128), %sp
122 sethi %hi(call_method), %g2
123 or %g2, %lo(call_method), %g2
124 stx %g2, [%sp + 2047 + 128 + 0x00]
126 stx %g2, [%sp + 2047 + 128 + 0x08]
128 stx %g2, [%sp + 2047 + 128 + 0x10]
129 sethi %hi(itlb_load), %g2
130 or %g2, %lo(itlb_load), %g2
131 stx %g2, [%sp + 2047 + 128 + 0x18]
132 sethi %hi(prom_mmu_ihandle_cache), %g2
133 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
134 stx %g2, [%sp + 2047 + 128 + 0x20]
135 sethi %hi(KERNBASE), %g2
136 stx %g2, [%sp + 2047 + 128 + 0x28]
137 sethi %hi(kern_locked_tte_data), %g2
138 ldx [%g2 + %lo(kern_locked_tte_data)], %g2
139 stx %g2, [%sp + 2047 + 128 + 0x30]
142 BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
146 stx %g2, [%sp + 2047 + 128 + 0x38]
147 sethi %hi(p1275buf), %g2
148 or %g2, %lo(p1275buf), %g2
149 ldx [%g2 + 0x08], %o1
151 add %sp, (2047 + 128), %o0
153 sethi %hi(bigkernel), %g2
154 lduw [%g2 + %lo(bigkernel)], %g2
158 sethi %hi(call_method), %g2
159 or %g2, %lo(call_method), %g2
160 stx %g2, [%sp + 2047 + 128 + 0x00]
162 stx %g2, [%sp + 2047 + 128 + 0x08]
164 stx %g2, [%sp + 2047 + 128 + 0x10]
165 sethi %hi(itlb_load), %g2
166 or %g2, %lo(itlb_load), %g2
167 stx %g2, [%sp + 2047 + 128 + 0x18]
168 sethi %hi(prom_mmu_ihandle_cache), %g2
169 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
170 stx %g2, [%sp + 2047 + 128 + 0x20]
171 sethi %hi(KERNBASE + 0x400000), %g2
172 stx %g2, [%sp + 2047 + 128 + 0x28]
173 sethi %hi(kern_locked_tte_data), %g2
174 ldx [%g2 + %lo(kern_locked_tte_data)], %g2
175 sethi %hi(0x400000), %g1
177 stx %g2, [%sp + 2047 + 128 + 0x30]
180 BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
184 stx %g2, [%sp + 2047 + 128 + 0x38]
185 sethi %hi(p1275buf), %g2
186 or %g2, %lo(p1275buf), %g2
187 ldx [%g2 + 0x08], %o1
189 add %sp, (2047 + 128), %o0
192 sethi %hi(call_method), %g2
193 or %g2, %lo(call_method), %g2
194 stx %g2, [%sp + 2047 + 128 + 0x00]
196 stx %g2, [%sp + 2047 + 128 + 0x08]
198 stx %g2, [%sp + 2047 + 128 + 0x10]
199 sethi %hi(dtlb_load), %g2
200 or %g2, %lo(dtlb_load), %g2
201 stx %g2, [%sp + 2047 + 128 + 0x18]
202 sethi %hi(prom_mmu_ihandle_cache), %g2
203 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
204 stx %g2, [%sp + 2047 + 128 + 0x20]
205 sethi %hi(KERNBASE), %g2
206 stx %g2, [%sp + 2047 + 128 + 0x28]
207 sethi %hi(kern_locked_tte_data), %g2
208 ldx [%g2 + %lo(kern_locked_tte_data)], %g2
209 stx %g2, [%sp + 2047 + 128 + 0x30]
212 BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
217 stx %g2, [%sp + 2047 + 128 + 0x38]
218 sethi %hi(p1275buf), %g2
219 or %g2, %lo(p1275buf), %g2
220 ldx [%g2 + 0x08], %o1
222 add %sp, (2047 + 128), %o0
224 sethi %hi(bigkernel), %g2
225 lduw [%g2 + %lo(bigkernel)], %g2
226 brz,pt %g2, do_unlock
229 sethi %hi(call_method), %g2
230 or %g2, %lo(call_method), %g2
231 stx %g2, [%sp + 2047 + 128 + 0x00]
233 stx %g2, [%sp + 2047 + 128 + 0x08]
235 stx %g2, [%sp + 2047 + 128 + 0x10]
236 sethi %hi(dtlb_load), %g2
237 or %g2, %lo(dtlb_load), %g2
238 stx %g2, [%sp + 2047 + 128 + 0x18]
239 sethi %hi(prom_mmu_ihandle_cache), %g2
240 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
241 stx %g2, [%sp + 2047 + 128 + 0x20]
242 sethi %hi(KERNBASE + 0x400000), %g2
243 stx %g2, [%sp + 2047 + 128 + 0x28]
244 sethi %hi(kern_locked_tte_data), %g2
245 ldx [%g2 + %lo(kern_locked_tte_data)], %g2
246 sethi %hi(0x400000), %g1
248 stx %g2, [%sp + 2047 + 128 + 0x30]
251 BRANCH_IF_ANY_CHEETAH(g1,g5,1f)
256 stx %g2, [%sp + 2047 + 128 + 0x38]
257 sethi %hi(p1275buf), %g2
258 or %g2, %lo(p1275buf), %g2
259 ldx [%g2 + 0x08], %o1
261 add %sp, (2047 + 128), %o0
264 sethi %hi(prom_entry_lock), %g2
265 stb %g0, [%g2 + %lo(prom_entry_lock)]
266 membar #StoreStore | #StoreLoad
268 ba,pt %xcc, after_lock_tlb
272 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
273 sethi %hi(KERNBASE), %o0
275 sethi %hi(kern_locked_tte_data), %o2
276 ldx [%o2 + %lo(kern_locked_tte_data)], %o2
280 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
281 sethi %hi(KERNBASE), %o0
283 sethi %hi(kern_locked_tte_data), %o2
284 ldx [%o2 + %lo(kern_locked_tte_data)], %o2
288 sethi %hi(bigkernel), %g2
289 lduw [%g2 + %lo(bigkernel)], %g2
290 brz,pt %g2, after_lock_tlb
293 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
294 sethi %hi(KERNBASE + 0x400000), %o0
296 sethi %hi(kern_locked_tte_data), %o2
297 ldx [%o2 + %lo(kern_locked_tte_data)], %o2
298 sethi %hi(0x400000), %o3
303 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
304 sethi %hi(KERNBASE + 0x400000), %o0
306 sethi %hi(kern_locked_tte_data), %o2
307 ldx [%o2 + %lo(kern_locked_tte_data)], %o2
308 sethi %hi(0x400000), %o3
314 wrpr %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
319 mov PRIMARY_CONTEXT, %g7
321 661: stxa %g0, [%g7] ASI_DMMU
322 .section .sun4v_1insn_patch, "ax"
324 stxa %g0, [%g7] ASI_MMU
328 mov SECONDARY_CONTEXT, %g7
330 661: stxa %g0, [%g7] ASI_DMMU
331 .section .sun4v_1insn_patch, "ax"
333 stxa %g0, [%g7] ASI_MMU
338 /* Everything we do here, until we properly take over the
339 * trap table, must be done with extreme care. We cannot
340 * make any references to %g6 (current thread pointer),
341 * %g4 (current task pointer), or %g5 (base of current cpu's
342 * per-cpu area) until we properly take over the trap table
343 * from the firmware and hypervisor.
345 * Get onto temporary stack which is in the locked kernel image.
347 sethi %hi(tramp_stack), %g1
348 or %g1, %lo(tramp_stack), %g1
349 add %g1, TRAMP_STACK_SIZE, %g1
350 sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
353 /* Put garbage in these registers to trap any access to them. */
358 call init_irqwork_curcpu
361 sethi %hi(tlb_type), %g3
362 lduw [%g3 + %lo(tlb_type)], %g2
367 call hard_smp_processor_id
370 call sun4v_register_mondo_queues
373 1: call init_cur_cpu_trap
376 /* Start using proper page size encodings in ctx register. */
377 sethi %hi(sparc64_kern_pri_context), %g3
378 ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
379 mov PRIMARY_CONTEXT, %g1
381 661: stxa %g2, [%g1] ASI_DMMU
382 .section .sun4v_1insn_patch, "ax"
384 stxa %g2, [%g1] ASI_MMU
391 /* As a hack, put &init_thread_union into %g6.
392 * prom_world() loads from here to restore the %asi
395 sethi %hi(init_thread_union), %g6
396 or %g6, %lo(init_thread_union), %g6
398 sethi %hi(is_sun4v), %o0
399 lduw [%o0 + %lo(is_sun4v)], %o0
403 TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
404 add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
405 stxa %g2, [%g0] ASI_SCRATCHPAD
407 /* Compute physical address:
409 * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
411 sethi %hi(KERNBASE), %g3
413 sethi %hi(kern_base), %g3
414 ldx [%g3 + %lo(kern_base)], %g3
416 sethi %hi(sparc64_ttable_tl0), %o0
418 set prom_set_trap_table_name, %g2
419 stx %g2, [%sp + 2047 + 128 + 0x00]
421 stx %g2, [%sp + 2047 + 128 + 0x08]
423 stx %g2, [%sp + 2047 + 128 + 0x10]
424 stx %o0, [%sp + 2047 + 128 + 0x18]
425 stx %o1, [%sp + 2047 + 128 + 0x20]
426 sethi %hi(p1275buf), %g2
427 or %g2, %lo(p1275buf), %g2
428 ldx [%g2 + 0x08], %o1
430 add %sp, (2047 + 128), %o0
435 1: sethi %hi(sparc64_ttable_tl0), %o0
436 set prom_set_trap_table_name, %g2
437 stx %g2, [%sp + 2047 + 128 + 0x00]
439 stx %g2, [%sp + 2047 + 128 + 0x08]
441 stx %g2, [%sp + 2047 + 128 + 0x10]
442 stx %o0, [%sp + 2047 + 128 + 0x18]
443 sethi %hi(p1275buf), %g2
444 or %g2, %lo(p1275buf), %g2
445 ldx [%g2 + 0x08], %o1
447 add %sp, (2047 + 128), %o0
450 ldx [%g6 + TI_TASK], %g4
453 sllx %g5, THREAD_SHIFT, %g5
454 sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
459 or %o1, PSTATE_IE, %o1
471 sparc64_cpu_startup_end: