blob: 7dd323234d7045a713e009a4955508decc28c16f [file] [log] [blame]
Jayachandran C65040e22011-11-16 00:21:28 +00001/*
2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3 * reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the NetLogic
9 * license below:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/init.h>
36
37#include <asm/asm.h>
38#include <asm/asm-offsets.h>
39#include <asm/regdef.h>
40#include <asm/mipsregs.h>
41#include <asm/stackframe.h>
42#include <asm/asmmacro.h>
43#include <asm/addrspace.h>
44
45#include <asm/netlogic/xlp-hal/iomap.h>
46#include <asm/netlogic/xlp-hal/xlp.h>
47#include <asm/netlogic/xlp-hal/sys.h>
48#include <asm/netlogic/xlp-hal/cpucontrol.h>
49
50#define CP0_EBASE $15
51#define SYS_CPU_COHERENT_BASE(node) CKSEG1ADDR(XLP_DEFAULT_IO_BASE) + \
52 XLP_IO_SYS_OFFSET(node) + XLP_IO_PCI_HDRSZ + \
53 SYS_CPU_NONCOHERENT_MODE * 4
54
55.macro __config_lsu
56 li t0, LSU_DEFEATURE
57 mfcr t1, t0
58
59 lui t2, 0x4080 /* Enable Unaligned Access, L2HPE */
60 or t1, t1, t2
61 li t2, ~0xe /* S1RCM */
62 and t1, t1, t2
63 mtcr t1, t0
64
65 li t0, SCHED_DEFEATURE
66 lui t1, 0x0100 /* Experimental: Disable BRU accepting ALU ops */
67 mtcr t1, t0
68.endm
69
70 .set noreorder
71 .set arch=xlr /* for mfcr/mtcr, XLR is sufficient */
72
73 __CPUINIT
74EXPORT(nlm_reset_entry)
75 mfc0 t0, CP0_EBASE, 1
76 mfc0 t1, CP0_EBASE, 1
77 srl t1, 5
78 andi t1, 0x3 /* t1 <- node */
79 li t2, 0x40000
80 mul t3, t2, t1 /* t3 = node * 0x40000 */
81 srl t0, t0, 2
82 and t0, t0, 0x7 /* t0 <- core */
83 li t1, 0x1
84 sll t0, t1, t0
85 nor t0, t0, zero /* t0 <- ~(1 << core) */
86 li t2, SYS_CPU_COHERENT_BASE(0)
87 add t2, t2, t3 /* t2 <- SYS offset for node */
88 lw t1, 0(t2)
89 and t1, t1, t0
90 sw t1, 0(t2)
91
92 /* read back to ensure complete */
93 lw t1, 0(t2)
94 sync
95
96 /* Configure LSU on Non-0 Cores. */
97 __config_lsu
98
99/*
100 * Wake up sibling threads from the initial thread in
101 * a core.
102 */
103EXPORT(nlm_boot_siblings)
104 li t0, CKSEG1ADDR(RESET_DATA_PHYS)
105 lw t1, BOOT_THREAD_MODE(t0) /* t1 <- thread mode */
106 li t0, ((CPU_BLOCKID_MAP << 8) | MAP_THREADMODE)
107 mfcr t2, t0
108 or t2, t2, t1
109 mtcr t2, t0
110
111 /*
112 * The new hardware thread starts at the next instruction
113 * For all the cases other than core 0 thread 0, we will
114 * jump to the secondary wait function.
115 */
116 mfc0 v0, CP0_EBASE, 1
117 andi v0, 0x7f /* v0 <- node/core */
118
119#if 1
120 /* A0 errata - Write MMU_SETUP after changing thread mode register. */
121 andi v1, v0, 0x3 /* v1 <- thread id */
122 bnez v1, 2f
123 nop
124
125 li t0, MMU_SETUP
126 li t1, 0
127 mtcr t1, t0
128 ehb
129#endif
130
1312: beqz v0, 3f
132 nop
133
134 /* setup status reg */
135 mfc0 t1, CP0_STATUS
136 li t0, ST0_BEV
137 or t1, t0
138 xor t1, t0
139#ifdef CONFIG_64BIT
140 ori t1, ST0_KX
141#endif
142 mtc0 t1, CP0_STATUS
143
144 /* SETUP TLBs for a mapped kernel here */
145 PTR_LA t0, prom_pre_boot_secondary_cpus
146 jalr t0
147 nop
148
149 /*
150 * For the boot CPU, we have to restore registers and
151 * return
152 */
1533: dmfc0 t0, $4, 2 /* restore SP from UserLocal */
154 li t1, 0xfadebeef
155 dmtc0 t1, $4, 2 /* restore SP from UserLocal */
156 PTR_SUBU sp, t0, PT_SIZE
157 RESTORE_ALL
158 jr ra
159 nop
160EXPORT(nlm_reset_entry_end)
161
162EXPORT(nlm_boot_core0_siblings) /* "Master" (n0c0t0) cpu starts from here */
163 __config_lsu
164 dmtc0 sp, $4, 2 /* SP saved in UserLocal */
165 SAVE_ALL
166 sync
167 /* find the location to which nlm_boot_siblings was relocated */
168 li t0, CKSEG1ADDR(RESET_VEC_PHYS)
169 dla t1, nlm_reset_entry
170 dla t2, nlm_boot_siblings
171 dsubu t2, t1
172 daddu t2, t0
173 /* call it */
174 jr t2
175 nop
176 __FINIT
177
178 __CPUINIT
179NESTED(prom_pre_boot_secondary_cpus, 16, sp)
180 .set mips64
181 mfc0 a0, CP0_EBASE, 1 /* read ebase */
182 andi a0, 0x3ff /* a0 has the processor_id() */
183 sll t0, a0, 2 /* offset in cpu array */
184
185 PTR_LA t1, nlm_cpu_ready /* mark CPU ready */
186 PTR_ADDU t1, t0
187 li t2, 1
188 sw t2, 0(t1)
189
190 PTR_LA t1, nlm_cpu_unblock
191 PTR_ADDU t1, t0
1921: lw t2, 0(t1) /* wait till unblocked */
193 bnez t2, 2f
194 nop
195 nop
196 nop
197 nop
198 nop
199 nop
200 j 1b
201 nop
202
2032: PTR_LA t1, nlm_next_sp
204 PTR_L sp, 0(t1)
205 PTR_LA t1, nlm_next_gp
206 PTR_L gp, 0(t1)
207
208 /* a0 has the processor id */
209 PTR_LA t0, nlm_early_init_secondary
210 jalr t0
211 nop
212
213 PTR_LA t0, smp_bootstrap
214 jr t0
215 nop
216END(prom_pre_boot_secondary_cpus)
217 __FINIT