2 * trampoline.S: Jump start slave processors on sparc64.
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
13 #include <asm/pstate.h>
15 #include <asm/pgtable.h>
16 #include <asm/spitfire.h>
17 #include <asm/processor.h>
18 #include <asm/thread_info.h>
20 #include <asm/hypervisor.h>
21 #include <asm/cpudata.h>
29 .asciz "SUNW,itlb-load"
32 .asciz "SUNW,dtlb-load"
34 #define TRAMP_STACK_SIZE 1024
37 .skip TRAMP_STACK_SIZE
40 .globl sparc64_cpu_startup, sparc64_cpu_startup_end
42 BRANCH_IF_SUN4V(g1, niagara_startup)
43 BRANCH_IF_CHEETAH_BASE(g1, g5, cheetah_startup)
44 BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1, g5, cheetah_plus_startup)
46 ba,pt %xcc, spitfire_startup
50 /* Preserve OBP chosen DCU and DCR register settings. */
51 ba,pt %xcc, cheetah_generic_startup
55 mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
58 sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
59 or %g5, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g5
61 or %g5, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g5
62 stxa %g5, [%g0] ASI_DCU_CONTROL_REG
66 cheetah_generic_startup:
67 mov TSB_EXTENSION_P, %g3
68 stxa %g0, [%g3] ASI_DMMU
69 stxa %g0, [%g3] ASI_IMMU
72 mov TSB_EXTENSION_S, %g3
73 stxa %g0, [%g3] ASI_DMMU
76 mov TSB_EXTENSION_N, %g3
77 stxa %g0, [%g3] ASI_DMMU
78 stxa %g0, [%g3] ASI_IMMU
83 /* Disable STICK_INT interrupts. */
84 sethi %hi(0x80000000), %g5
88 ba,pt %xcc, startup_continue
92 mov (LSU_CONTROL_IC | LSU_CONTROL_DC | LSU_CONTROL_IM | LSU_CONTROL_DM), %g1
93 stxa %g1, [%g0] ASI_LSU_CONTROL
98 BRANCH_IF_SUN4V(g1, niagara_lock_tlb)
100 sethi %hi(0x80000000), %g2
102 wr %g2, 0, %tick_cmpr
104 /* Call OBP by hand to lock KERNBASE into i/d tlbs.
105 * We lock 'num_kernel_image_mappings' consequetive entries.
107 sethi %hi(prom_entry_lock), %g2
108 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
112 /* Get onto temporary stack which will be in the locked
115 sethi %hi(tramp_stack), %g1
116 or %g1, %lo(tramp_stack), %g1
117 add %g1, TRAMP_STACK_SIZE, %g1
118 sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
121 /* Setup the loop variables:
124 * %l5: Loop iterator, iterates from 0 to 'num_kernel_image_mappings'
125 * %l6: Number of TTE entries to map
126 * %l7: Highest TTE entry number, we count down
128 sethi %hi(KERNBASE), %l3
129 sethi %hi(kern_locked_tte_data), %l4
130 ldx [%l4 + %lo(kern_locked_tte_data)], %l4
132 sethi %hi(num_kernel_image_mappings), %l6
133 lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
136 BRANCH_IF_ANY_CHEETAH(g1,g5,2f)
142 /* Lock into I-MMU */
143 sethi %hi(call_method), %g2
144 or %g2, %lo(call_method), %g2
145 stx %g2, [%sp + 2047 + 128 + 0x00]
147 stx %g2, [%sp + 2047 + 128 + 0x08]
149 stx %g2, [%sp + 2047 + 128 + 0x10]
150 sethi %hi(itlb_load), %g2
151 or %g2, %lo(itlb_load), %g2
152 stx %g2, [%sp + 2047 + 128 + 0x18]
153 sethi %hi(prom_mmu_ihandle_cache), %g2
154 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
155 stx %g2, [%sp + 2047 + 128 + 0x20]
157 /* Each TTE maps 4MB, convert index to offset. */
161 stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
163 stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
165 /* TTE index is highest minus loop index. */
167 stx %g2, [%sp + 2047 + 128 + 0x38]
169 sethi %hi(p1275buf), %g2
170 or %g2, %lo(p1275buf), %g2
171 ldx [%g2 + 0x08], %o1
173 add %sp, (2047 + 128), %o0
175 /* Lock into D-MMU */
176 sethi %hi(call_method), %g2
177 or %g2, %lo(call_method), %g2
178 stx %g2, [%sp + 2047 + 128 + 0x00]
180 stx %g2, [%sp + 2047 + 128 + 0x08]
182 stx %g2, [%sp + 2047 + 128 + 0x10]
183 sethi %hi(dtlb_load), %g2
184 or %g2, %lo(dtlb_load), %g2
185 stx %g2, [%sp + 2047 + 128 + 0x18]
186 sethi %hi(prom_mmu_ihandle_cache), %g2
187 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
188 stx %g2, [%sp + 2047 + 128 + 0x20]
190 /* Each TTE maps 4MB, convert index to offset. */
194 stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
196 stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
198 /* TTE index is highest minus loop index. */
200 stx %g2, [%sp + 2047 + 128 + 0x38]
202 sethi %hi(p1275buf), %g2
203 or %g2, %lo(p1275buf), %g2
204 ldx [%g2 + 0x08], %o1
206 add %sp, (2047 + 128), %o0
213 sethi %hi(prom_entry_lock), %g2
214 stb %g0, [%g2 + %lo(prom_entry_lock)]
216 ba,pt %xcc, after_lock_tlb
220 sethi %hi(KERNBASE), %l3
221 sethi %hi(kern_locked_tte_data), %l4
222 ldx [%l4 + %lo(kern_locked_tte_data)], %l4
224 sethi %hi(num_kernel_image_mappings), %l6
225 lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
228 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
236 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
250 wrpr %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
255 mov PRIMARY_CONTEXT, %g7
257 661: stxa %g0, [%g7] ASI_DMMU
258 .section .sun4v_1insn_patch, "ax"
260 stxa %g0, [%g7] ASI_MMU
264 mov SECONDARY_CONTEXT, %g7
266 661: stxa %g0, [%g7] ASI_DMMU
267 .section .sun4v_1insn_patch, "ax"
269 stxa %g0, [%g7] ASI_MMU
274 /* Everything we do here, until we properly take over the
275 * trap table, must be done with extreme care. We cannot
276 * make any references to %g6 (current thread pointer),
277 * %g4 (current task pointer), or %g5 (base of current cpu's
278 * per-cpu area) until we properly take over the trap table
279 * from the firmware and hypervisor.
281 * Get onto temporary stack which is in the locked kernel image.
283 sethi %hi(tramp_stack), %g1
284 or %g1, %lo(tramp_stack), %g1
285 add %g1, TRAMP_STACK_SIZE, %g1
286 sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
289 /* Put garbage in these registers to trap any access to them. */
294 call init_irqwork_curcpu
297 sethi %hi(tlb_type), %g3
298 lduw [%g3 + %lo(tlb_type)], %g2
303 call hard_smp_processor_id
306 call sun4v_register_mondo_queues
309 1: call init_cur_cpu_trap
312 /* Start using proper page size encodings in ctx register. */
313 sethi %hi(sparc64_kern_pri_context), %g3
314 ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
315 mov PRIMARY_CONTEXT, %g1
317 661: stxa %g2, [%g1] ASI_DMMU
318 .section .sun4v_1insn_patch, "ax"
320 stxa %g2, [%g1] ASI_MMU
327 sethi %hi(prom_entry_lock), %g2
328 1: ldstub [%g2 + %lo(prom_entry_lock)], %g1
332 /* As a hack, put &init_thread_union into %g6.
333 * prom_world() loads from here to restore the %asi
336 sethi %hi(init_thread_union), %g6
337 or %g6, %lo(init_thread_union), %g6
339 sethi %hi(is_sun4v), %o0
340 lduw [%o0 + %lo(is_sun4v)], %o0
344 TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
345 add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
346 stxa %g2, [%g0] ASI_SCRATCHPAD
348 /* Compute physical address:
350 * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
352 sethi %hi(KERNBASE), %g3
354 sethi %hi(kern_base), %g3
355 ldx [%g3 + %lo(kern_base)], %g3
357 sethi %hi(sparc64_ttable_tl0), %o0
359 set prom_set_trap_table_name, %g2
360 stx %g2, [%sp + 2047 + 128 + 0x00]
362 stx %g2, [%sp + 2047 + 128 + 0x08]
364 stx %g2, [%sp + 2047 + 128 + 0x10]
365 stx %o0, [%sp + 2047 + 128 + 0x18]
366 stx %o1, [%sp + 2047 + 128 + 0x20]
367 sethi %hi(p1275buf), %g2
368 or %g2, %lo(p1275buf), %g2
369 ldx [%g2 + 0x08], %o1
371 add %sp, (2047 + 128), %o0
376 2: sethi %hi(sparc64_ttable_tl0), %o0
377 set prom_set_trap_table_name, %g2
378 stx %g2, [%sp + 2047 + 128 + 0x00]
380 stx %g2, [%sp + 2047 + 128 + 0x08]
382 stx %g2, [%sp + 2047 + 128 + 0x10]
383 stx %o0, [%sp + 2047 + 128 + 0x18]
384 sethi %hi(p1275buf), %g2
385 or %g2, %lo(p1275buf), %g2
386 ldx [%g2 + 0x08], %o1
388 add %sp, (2047 + 128), %o0
390 3: sethi %hi(prom_entry_lock), %g2
391 stb %g0, [%g2 + %lo(prom_entry_lock)]
394 ldx [%g6 + TI_TASK], %g4
397 sllx %g5, THREAD_SHIFT, %g5
398 sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
402 or %o1, PSTATE_IE, %o1
413 sparc64_cpu_startup_end: