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 'num_kernel_image_mappings' consequetive entries.
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 /* Setup the loop variables:
125 * %l5: Loop iterator, iterates from 0 to 'num_kernel_image_mappings'
126 * %l6: Number of TTE entries to map
127 * %l7: Highest TTE entry number, we count down
129 sethi %hi(KERNBASE), %l3
130 sethi %hi(kern_locked_tte_data), %l4
131 ldx [%l4 + %lo(kern_locked_tte_data)], %l4
133 sethi %hi(num_kernel_image_mappings), %l6
134 lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
138 BRANCH_IF_ANY_CHEETAH(g1,g5,2f)
144 /* Lock into I-MMU */
145 sethi %hi(call_method), %g2
146 or %g2, %lo(call_method), %g2
147 stx %g2, [%sp + 2047 + 128 + 0x00]
149 stx %g2, [%sp + 2047 + 128 + 0x08]
151 stx %g2, [%sp + 2047 + 128 + 0x10]
152 sethi %hi(itlb_load), %g2
153 or %g2, %lo(itlb_load), %g2
154 stx %g2, [%sp + 2047 + 128 + 0x18]
155 sethi %hi(prom_mmu_ihandle_cache), %g2
156 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
157 stx %g2, [%sp + 2047 + 128 + 0x20]
159 /* Each TTE maps 4MB, convert index to offset. */
163 stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
165 stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
167 /* TTE index is highest minus loop index. */
169 stx %g2, [%sp + 2047 + 128 + 0x38]
171 sethi %hi(p1275buf), %g2
172 or %g2, %lo(p1275buf), %g2
173 ldx [%g2 + 0x08], %o1
175 add %sp, (2047 + 128), %o0
177 /* Lock into D-MMU */
178 sethi %hi(call_method), %g2
179 or %g2, %lo(call_method), %g2
180 stx %g2, [%sp + 2047 + 128 + 0x00]
182 stx %g2, [%sp + 2047 + 128 + 0x08]
184 stx %g2, [%sp + 2047 + 128 + 0x10]
185 sethi %hi(dtlb_load), %g2
186 or %g2, %lo(dtlb_load), %g2
187 stx %g2, [%sp + 2047 + 128 + 0x18]
188 sethi %hi(prom_mmu_ihandle_cache), %g2
189 lduw [%g2 + %lo(prom_mmu_ihandle_cache)], %g2
190 stx %g2, [%sp + 2047 + 128 + 0x20]
192 /* Each TTE maps 4MB, convert index to offset. */
196 stx %g2, [%sp + 2047 + 128 + 0x28] ! VADDR
198 stx %g2, [%sp + 2047 + 128 + 0x30] ! TTE
200 /* TTE index is highest minus loop index. */
202 stx %g2, [%sp + 2047 + 128 + 0x38]
204 sethi %hi(p1275buf), %g2
205 or %g2, %lo(p1275buf), %g2
206 ldx [%g2 + 0x08], %o1
208 add %sp, (2047 + 128), %o0
215 sethi %hi(prom_entry_lock), %g2
216 stb %g0, [%g2 + %lo(prom_entry_lock)]
217 membar #StoreStore | #StoreLoad
219 ba,pt %xcc, after_lock_tlb
223 sethi %hi(KERNBASE), %l3
224 sethi %hi(kern_locked_tte_data), %l4
225 ldx [%l4 + %lo(kern_locked_tte_data)], %l4
227 sethi %hi(num_kernel_image_mappings), %l6
228 lduw [%l6 + %lo(num_kernel_image_mappings)], %l6
232 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
240 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
254 wrpr %g0, (PSTATE_PRIV | PSTATE_PEF), %pstate
259 mov PRIMARY_CONTEXT, %g7
261 661: stxa %g0, [%g7] ASI_DMMU
262 .section .sun4v_1insn_patch, "ax"
264 stxa %g0, [%g7] ASI_MMU
268 mov SECONDARY_CONTEXT, %g7
270 661: stxa %g0, [%g7] ASI_DMMU
271 .section .sun4v_1insn_patch, "ax"
273 stxa %g0, [%g7] ASI_MMU
278 /* Everything we do here, until we properly take over the
279 * trap table, must be done with extreme care. We cannot
280 * make any references to %g6 (current thread pointer),
281 * %g4 (current task pointer), or %g5 (base of current cpu's
282 * per-cpu area) until we properly take over the trap table
283 * from the firmware and hypervisor.
285 * Get onto temporary stack which is in the locked kernel image.
287 sethi %hi(tramp_stack), %g1
288 or %g1, %lo(tramp_stack), %g1
289 add %g1, TRAMP_STACK_SIZE, %g1
290 sub %g1, STACKFRAME_SZ + STACK_BIAS + 256, %sp
293 /* Put garbage in these registers to trap any access to them. */
298 call init_irqwork_curcpu
301 sethi %hi(tlb_type), %g3
302 lduw [%g3 + %lo(tlb_type)], %g2
307 call hard_smp_processor_id
310 call sun4v_register_mondo_queues
313 1: call init_cur_cpu_trap
316 /* Start using proper page size encodings in ctx register. */
317 sethi %hi(sparc64_kern_pri_context), %g3
318 ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
319 mov PRIMARY_CONTEXT, %g1
321 661: stxa %g2, [%g1] ASI_DMMU
322 .section .sun4v_1insn_patch, "ax"
324 stxa %g2, [%g1] ASI_MMU
331 /* As a hack, put &init_thread_union into %g6.
332 * prom_world() loads from here to restore the %asi
335 sethi %hi(init_thread_union), %g6
336 or %g6, %lo(init_thread_union), %g6
338 sethi %hi(is_sun4v), %o0
339 lduw [%o0 + %lo(is_sun4v)], %o0
343 TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
344 add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
345 stxa %g2, [%g0] ASI_SCRATCHPAD
347 /* Compute physical address:
349 * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
351 sethi %hi(KERNBASE), %g3
353 sethi %hi(kern_base), %g3
354 ldx [%g3 + %lo(kern_base)], %g3
356 sethi %hi(sparc64_ttable_tl0), %o0
358 set prom_set_trap_table_name, %g2
359 stx %g2, [%sp + 2047 + 128 + 0x00]
361 stx %g2, [%sp + 2047 + 128 + 0x08]
363 stx %g2, [%sp + 2047 + 128 + 0x10]
364 stx %o0, [%sp + 2047 + 128 + 0x18]
365 stx %o1, [%sp + 2047 + 128 + 0x20]
366 sethi %hi(p1275buf), %g2
367 or %g2, %lo(p1275buf), %g2
368 ldx [%g2 + 0x08], %o1
370 add %sp, (2047 + 128), %o0
375 1: sethi %hi(sparc64_ttable_tl0), %o0
376 set prom_set_trap_table_name, %g2
377 stx %g2, [%sp + 2047 + 128 + 0x00]
379 stx %g2, [%sp + 2047 + 128 + 0x08]
381 stx %g2, [%sp + 2047 + 128 + 0x10]
382 stx %o0, [%sp + 2047 + 128 + 0x18]
383 sethi %hi(p1275buf), %g2
384 or %g2, %lo(p1275buf), %g2
385 ldx [%g2 + 0x08], %o1
387 add %sp, (2047 + 128), %o0
390 ldx [%g6 + TI_TASK], %g4
393 sllx %g5, THREAD_SHIFT, %g5
394 sub %g5, (STACKFRAME_SZ + STACK_BIAS), %g5
399 or %o1, PSTATE_IE, %o1
411 sparc64_cpu_startup_end: