17 #include <linux/types.h>
26 #define SCOM_RAMC 0x2a
27 #define SCOM_RAMC_TGT1_EXT 0x80000000
28 #define SCOM_RAMC_SRC1_EXT 0x40000000
29 #define SCOM_RAMC_SRC2_EXT 0x20000000
30 #define SCOM_RAMC_SRC3_EXT 0x10000000
31 #define SCOM_RAMC_ENABLE 0x00080000
32 #define SCOM_RAMC_THREADSEL 0x00060000
33 #define SCOM_RAMC_EXECUTE 0x00010000
34 #define SCOM_RAMC_MSR_OVERRIDE 0x00008000
35 #define SCOM_RAMC_MSR_PR 0x00004000
36 #define SCOM_RAMC_MSR_GS 0x00002000
37 #define SCOM_RAMC_FORCE 0x00001000
38 #define SCOM_RAMC_FLUSH 0x00000800
39 #define SCOM_RAMC_INTERRUPT 0x00000004
40 #define SCOM_RAMC_ERROR 0x00000002
41 #define SCOM_RAMC_DONE 0x00000001
42 #define SCOM_RAMI 0x29
43 #define SCOM_RAMIC 0x28
44 #define SCOM_RAMIC_INSN 0xffffffff00000000
45 #define SCOM_RAMD 0x2d
46 #define SCOM_RAMDH 0x2e
47 #define SCOM_RAMDL 0x2f
48 #define SCOM_PCCR0 0x33
49 #define SCOM_PCCR0_ENABLE_DEBUG 0x80000000
50 #define SCOM_PCCR0_ENABLE_RAM 0x40000000
51 #define SCOM_THRCTL 0x30
52 #define SCOM_THRCTL_T0_STOP 0x80000000
53 #define SCOM_THRCTL_T1_STOP 0x40000000
54 #define SCOM_THRCTL_T2_STOP 0x20000000
55 #define SCOM_THRCTL_T3_STOP 0x10000000
56 #define SCOM_THRCTL_T0_STEP 0x08000000
57 #define SCOM_THRCTL_T1_STEP 0x04000000
58 #define SCOM_THRCTL_T2_STEP 0x02000000
59 #define SCOM_THRCTL_T3_STEP 0x01000000
60 #define SCOM_THRCTL_T0_RUN 0x00800000
61 #define SCOM_THRCTL_T1_RUN 0x00400000
62 #define SCOM_THRCTL_T2_RUN 0x00200000
63 #define SCOM_THRCTL_T3_RUN 0x00100000
64 #define SCOM_THRCTL_T0_PM 0x00080000
65 #define SCOM_THRCTL_T1_PM 0x00040000
66 #define SCOM_THRCTL_T2_PM 0x00020000
67 #define SCOM_THRCTL_T3_PM 0x00010000
68 #define SCOM_THRCTL_T0_UDE 0x00008000
69 #define SCOM_THRCTL_T1_UDE 0x00004000
70 #define SCOM_THRCTL_T2_UDE 0x00002000
71 #define SCOM_THRCTL_T3_UDE 0x00001000
72 #define SCOM_THRCTL_ASYNC_DIS 0x00000800
73 #define SCOM_THRCTL_TB_DIS 0x00000400
74 #define SCOM_THRCTL_DEC_DIS 0x00000200
75 #define SCOM_THRCTL_AND 0x31
76 #define SCOM_THRCTL_OR 0x32
81 static scom_map_t get_scom(
int cpu,
struct device_node *np,
int *first_thread)
83 scom_map_t scom =
per_cpu(scom_ptrs, cpu);
86 if (scom_map_ok(scom)) {
95 for (tcpu = cpu_first_thread_sibling(cpu);
96 tcpu <= cpu_last_thread_sibling(cpu); tcpu++)
97 per_cpu(scom_ptrs, tcpu) = scom;
102 if (cpu_first_thread_sibling(cpu) == 0)
108 static int a2_scom_ram(scom_map_t scom,
int thread,
u32 insn,
int extmask)
113 cmd = ((
u64)insn << 32) | (((
u64)extmask & 0xf) << 28)
119 while (!((val = scom_read(scom,
SCOM_RAMC)) & mask)) {
120 pr_devel(
"Waiting on RAMC = 0x%llx\n", val);
122 pr_err(
"RAMC timeout on instruction 0x%08x, thread %d\n",
129 pr_err(
"RAMC interrupt on instruction 0x%08x, thread %d\n",
135 pr_err(
"RAMC error on instruction 0x%08x, thread %d\n",
143 static int a2_scom_getgpr(scom_map_t scom,
int thread,
int gpr,
int alt,
149 u32 insn = 0x7c000378 | (gpr << 21) | (gpr << 16) | (gpr << 11);
150 rc = a2_scom_ram(scom, thread, insn, alt ? 0xf : 0x0);
159 static int a2_scom_getspr(scom_map_t scom,
int thread,
int spr,
u64 *out_spr)
161 int rc, sprhi, sprlo;
166 insn = 0x7c2002a6 | (sprlo << 16) | (sprhi << 11);
171 rc = a2_scom_ram(scom, thread, insn, 0xf);
174 return a2_scom_getgpr(scom, thread, 1, 1, out_spr);
177 static int a2_scom_setgpr(scom_map_t scom,
int thread,
int gpr,
180 u32 lis = 0x3c000000 | (gpr << 21);
181 u32 li = 0x38000000 | (gpr << 21);
182 u32 oris = 0x64000000 | (gpr << 21) | (gpr << 16);
183 u32 ori = 0x60000000 | (gpr << 21) | (gpr << 16);
184 u32 rldicr32 = 0x780007c6 | (gpr << 21) | (gpr << 16);
187 u32 high = (val >> 16) & 0xffff;
189 int lext = alt ? 0x8 : 0x0;
190 int oext = alt ? 0xf : 0x0;
194 rc |= a2_scom_ram(scom, thread, lis | highest, lext);
198 rc |= a2_scom_ram(scom, thread, oris | higher, oext);
200 rc |= a2_scom_ram(scom, thread, li | higher, lext);
203 if (highest || higher)
204 rc |= a2_scom_ram(scom, thread, rldicr32, oext);
207 if (highest || higher)
208 rc |= a2_scom_ram(scom, thread, oris | high, oext);
210 rc |= a2_scom_ram(scom, thread, lis | high, lext);
213 if (highest || higher || high)
214 rc |= a2_scom_ram(scom, thread, ori | low, oext);
216 rc |= a2_scom_ram(scom, thread, li | low, lext);
221 static int a2_scom_setspr(scom_map_t scom,
int thread,
int spr,
u64 val)
223 int sprhi = spr >> 5;
224 int sprlo = spr & 0x1f;
226 u32 insn = 0x7c2003a6 | (sprlo << 16) | (sprhi << 11);
231 if (a2_scom_setgpr(scom, thread, 1, 1, val))
234 return a2_scom_ram(scom, thread, insn, 0xf);
237 static int a2_scom_initial_tlb(scom_map_t scom,
int thread)
239 extern u32 a2_tlbinit_code_start[], a2_tlbinit_code_end[];
240 extern u32 a2_tlbinit_after_iprot_flush[];
241 extern u32 a2_tlbinit_after_linear_map[];
249 rc = a2_scom_getspr(scom, thread, SPRN_TLB0CFG, &tlbcfg);
257 a2_scom_setspr(scom, thread,
SPRN_MMUCR2, 0x000a7531);
259 a2_scom_setspr(scom, thread,
SPRN_MMUCR3, 0x0000000f);
263 a2_scom_setspr(scom, thread, SPRN_MAS2, epn);
264 for (i = 0; i <
entries; i++) {
266 a2_scom_setspr(scom, thread, SPRN_MAS0,
MAS0_ESEL(i % assoc));
269 rc = a2_scom_ram(scom, thread, 0x7c0007a4, 0);
274 if((i + 1) % assoc == 0) {
276 a2_scom_setspr(scom, thread, SPRN_MAS2, epn);
281 rc = a2_scom_setgpr(scom, thread, 3, 0,
MAS0_TLBSEL(0));
286 for (p = a2_tlbinit_code_start; p < a2_tlbinit_after_linear_map; p++) {
287 rc = a2_scom_ram(scom, thread, *p, 0);
301 for (p = a2_tlbinit_after_iprot_flush; p < a2_tlbinit_code_end; p++) {
302 rc = a2_scom_ram(scom, thread, *p, 0);
309 pr_err(
"Setting up initial TLB failed, err %d\n", rc);
311 if (rc == -SCOM_RAMC_INTERRUPT) {
314 u64 iar, srr0, srr1,
esr, mas0, mas1, mas2, mas7_3, mas8, ccr2;
315 rc[0] = a2_scom_getspr(scom, thread,
SPRN_IAR, &iar);
316 rc[1] = a2_scom_getspr(scom, thread, SPRN_SRR0, &srr0);
317 rc[2] = a2_scom_getspr(scom, thread, SPRN_SRR1, &srr1);
318 rc[3] = a2_scom_getspr(scom, thread, SPRN_ESR, &esr);
319 rc[4] = a2_scom_getspr(scom, thread, SPRN_MAS0, &mas0);
320 rc[5] = a2_scom_getspr(scom, thread, SPRN_MAS1, &mas1);
321 rc[6] = a2_scom_getspr(scom, thread, SPRN_MAS2, &mas2);
322 rc[7] = a2_scom_getspr(scom, thread, SPRN_MAS7_MAS3, &mas7_3);
323 rc[8] = a2_scom_getspr(scom, thread, SPRN_MAS8, &mas8);
324 rc[9] = a2_scom_getspr(scom, thread,
SPRN_A2_CCR2, &ccr2);
325 pr_err(
" -> retreived IAR =0x%llx (err %d)\n", iar, rc[0]);
326 pr_err(
" retreived SRR0=0x%llx (err %d)\n", srr0, rc[1]);
327 pr_err(
" retreived SRR1=0x%llx (err %d)\n", srr1, rc[2]);
328 pr_err(
" retreived ESR =0x%llx (err %d)\n", esr, rc[3]);
329 pr_err(
" retreived MAS0=0x%llx (err %d)\n", mas0, rc[4]);
330 pr_err(
" retreived MAS1=0x%llx (err %d)\n", mas1, rc[5]);
331 pr_err(
" retreived MAS2=0x%llx (err %d)\n", mas2, rc[6]);
332 pr_err(
" retreived MS73=0x%llx (err %d)\n", mas7_3, rc[7]);
333 pr_err(
" retreived MAS8=0x%llx (err %d)\n", mas8, rc[8]);
334 pr_err(
" retreived CCR2=0x%llx (err %d)\n", ccr2, rc[9]);
343 u64 init_iar, init_msr, init_ccr2;
344 unsigned long start_here;
349 scom = get_scom(lcpu, np, &core_setup);
355 pr_devel(
"Bringing up CPU%d using SCOM...\n", lcpu);
378 a2_scom_getspr(scom, thr_idx,
SPRN_IAR, &init_iar);
379 a2_scom_getspr(scom, thr_idx, 0x0ff0, &init_msr);
380 a2_scom_getspr(scom, thr_idx,
SPRN_A2_CCR2, &init_ccr2);
383 rc = a2_scom_setspr(scom, thr_idx, 0x0ff0, MSR_CM);
385 pr_err(
"Failed to set MSR ! err %d\n", rc);
390 a2_scom_ram(scom, thr_idx, 0x7c0004ac, 0);
391 a2_scom_ram(scom, thr_idx, 0x4c00012c, 0);
394 pr_devel(
"CPU%d is first thread in core, initializing TLB...\n",
396 rc = a2_scom_initial_tlb(scom, thr_idx);
401 start_here = *(
unsigned long *)(core_setup ? generic_secondary_smp_init
402 : generic_secondary_thread_init);
403 pr_devel(
"CPU%d entry point at 0x%lx...\n", lcpu, start_here);
405 rc |= a2_scom_setspr(scom, thr_idx,
SPRN_IAR, start_here);
406 rc |= a2_scom_setgpr(scom, thr_idx, 3, 0,
407 get_hard_smp_processor_id(lcpu));
412 rc |= a2_scom_setgpr(scom, thr_idx, 4, 0, 1);
414 rc |= a2_scom_setspr(scom, thr_idx,
SPRN_TENS, 0x1 << thr_idx);
420 pr_devel(
" SCOM initialization %s\n", rc ?
"failed" :
"succeeded");
422 pr_err(
"Old IAR=0x%08llx MSR=0x%08llx CCR2=0x%08llx\n",
423 init_iar, init_msr, init_ccr2);