blob: f2663e460d374cc6e9626e2ebd284ddfcde47d8c [file] [log] [blame]
Paul Burton0ee958e2014-01-15 10:31:53 +00001/*
2 * Copyright (C) 2013 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <asm/addrspace.h>
12#include <asm/asm.h>
13#include <asm/asm-offsets.h>
14#include <asm/asmmacro.h>
15#include <asm/cacheops.h>
Markos Chandras6521d9a2014-07-21 14:35:56 +010016#include <asm/eva.h>
Paul Burton0ee958e2014-01-15 10:31:53 +000017#include <asm/mipsregs.h>
Paul Burton245a7862014-04-14 12:04:27 +010018#include <asm/mipsmtregs.h>
Paul Burton3179d372014-04-14 11:00:56 +010019#include <asm/pm.h>
Paul Burton0ee958e2014-01-15 10:31:53 +000020
Paul Burton245a7862014-04-14 12:04:27 +010021#define GCR_CL_COHERENCE_OFS 0x2008
22#define GCR_CL_ID_OFS 0x2028
23
24.extern mips_cm_base
25
26.set noreorder
27
Paul Burton8fe2c5472015-09-22 11:12:10 -070028#ifdef CONFIG_64BIT
29# define STATUS_BITDEPS ST0_KX
30#else
31# define STATUS_BITDEPS 0
32#endif
33
Paul Burton245a7862014-04-14 12:04:27 +010034 /*
35 * Set dest to non-zero if the core supports the MT ASE, else zero. If
36 * MT is not supported then branch to nomt.
37 */
38 .macro has_mt dest, nomt
39 mfc0 \dest, CP0_CONFIG
40 bgez \dest, \nomt
41 mfc0 \dest, CP0_CONFIG, 1
42 bgez \dest, \nomt
43 mfc0 \dest, CP0_CONFIG, 2
44 bgez \dest, \nomt
45 mfc0 \dest, CP0_CONFIG, 3
46 andi \dest, \dest, MIPS_CONF3_MT
47 beqz \dest, \nomt
Paul Burton1e5fb282015-08-05 15:42:36 -070048 nop
Paul Burton245a7862014-04-14 12:04:27 +010049 .endm
Paul Burton0ee958e2014-01-15 10:31:53 +000050
51.section .text.cps-vec
52.balign 0x1000
Paul Burton0ee958e2014-01-15 10:31:53 +000053
54LEAF(mips_cps_core_entry)
55 /*
Paul Burton0155a062014-04-16 11:10:57 +010056 * These first 12 bytes will be patched by cps_smp_setup to load the
57 * base address of the CM GCRs into register v1 and the CCA to use into
58 * register s0.
Paul Burton0ee958e2014-01-15 10:31:53 +000059 */
60 .quad 0
Paul Burton0155a062014-04-16 11:10:57 +010061 .word 0
Paul Burton0ee958e2014-01-15 10:31:53 +000062
63 /* Check whether we're here due to an NMI */
64 mfc0 k0, CP0_STATUS
65 and k0, k0, ST0_NMI
66 beqz k0, not_nmi
67 nop
68
69 /* This is an NMI */
Markos Chandras81a02e32015-07-01 09:13:29 +010070 PTR_LA k0, nmi_handler
Paul Burton0ee958e2014-01-15 10:31:53 +000071 jr k0
72 nop
73
74not_nmi:
75 /* Setup Cause */
76 li t0, CAUSEF_IV
77 mtc0 t0, CP0_CAUSE
78
79 /* Setup Status */
Paul Burton8fe2c5472015-09-22 11:12:10 -070080 li t0, ST0_CU1 | ST0_CU0 | ST0_BEV | STATUS_BITDEPS
Paul Burton0ee958e2014-01-15 10:31:53 +000081 mtc0 t0, CP0_STATUS
82
83 /*
84 * Clear the bits used to index the caches. Note that the architecture
85 * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
86 * be valid for all MIPS32 CPUs, even those for which said writes are
87 * unnecessary.
88 */
89 mtc0 zero, CP0_TAGLO, 0
90 mtc0 zero, CP0_TAGHI, 0
91 mtc0 zero, CP0_TAGLO, 2
92 mtc0 zero, CP0_TAGHI, 2
93 ehb
94
95 /* Primary cache configuration is indicated by Config1 */
96 mfc0 v0, CP0_CONFIG, 1
97
98 /* Detect I-cache line size */
99 _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
100 beqz t0, icache_done
101 li t1, 2
102 sllv t0, t1, t0
103
104 /* Detect I-cache size */
105 _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
106 xori t2, t1, 0x7
107 beqz t2, 1f
108 li t3, 32
Markos Chandrasacac4102014-11-24 14:40:11 +0000109 addiu t1, t1, 1
Paul Burton0ee958e2014-01-15 10:31:53 +0000110 sllv t1, t3, t1
1111: /* At this point t1 == I-cache sets per way */
112 _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
Markos Chandrasacac4102014-11-24 14:40:11 +0000113 addiu t2, t2, 1
Paul Burton0ee958e2014-01-15 10:31:53 +0000114 mul t1, t1, t0
115 mul t1, t1, t2
116
Markos Chandras717f1422015-07-01 09:13:32 +0100117 li a0, CKSEG0
Markos Chandrasb677bc02015-07-01 09:13:33 +0100118 PTR_ADD a1, a0, t1
Paul Burton0ee958e2014-01-15 10:31:53 +00001191: cache Index_Store_Tag_I, 0(a0)
Markos Chandrasb677bc02015-07-01 09:13:33 +0100120 PTR_ADD a0, a0, t0
Paul Burton0ee958e2014-01-15 10:31:53 +0000121 bne a0, a1, 1b
122 nop
123icache_done:
124
125 /* Detect D-cache line size */
126 _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
127 beqz t0, dcache_done
128 li t1, 2
129 sllv t0, t1, t0
130
131 /* Detect D-cache size */
132 _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
133 xori t2, t1, 0x7
134 beqz t2, 1f
135 li t3, 32
Markos Chandrasacac4102014-11-24 14:40:11 +0000136 addiu t1, t1, 1
Paul Burton0ee958e2014-01-15 10:31:53 +0000137 sllv t1, t3, t1
1381: /* At this point t1 == D-cache sets per way */
139 _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
Markos Chandrasacac4102014-11-24 14:40:11 +0000140 addiu t2, t2, 1
Paul Burton0ee958e2014-01-15 10:31:53 +0000141 mul t1, t1, t0
142 mul t1, t1, t2
143
Markos Chandras717f1422015-07-01 09:13:32 +0100144 li a0, CKSEG0
Markos Chandrasb677bc02015-07-01 09:13:33 +0100145 PTR_ADDU a1, a0, t1
146 PTR_SUBU a1, a1, t0
Paul Burton0ee958e2014-01-15 10:31:53 +00001471: cache Index_Store_Tag_D, 0(a0)
148 bne a0, a1, 1b
Markos Chandrasb677bc02015-07-01 09:13:33 +0100149 PTR_ADD a0, a0, t0
Paul Burton0ee958e2014-01-15 10:31:53 +0000150dcache_done:
151
Paul Burton0155a062014-04-16 11:10:57 +0100152 /* Set Kseg0 CCA to that in s0 */
Paul Burton0ee958e2014-01-15 10:31:53 +0000153 mfc0 t0, CP0_CONFIG
154 ori t0, 0x7
Paul Burton0155a062014-04-16 11:10:57 +0100155 xori t0, 0x7
156 or t0, t0, s0
Paul Burton0ee958e2014-01-15 10:31:53 +0000157 mtc0 t0, CP0_CONFIG
158 ehb
159
160 /* Enter the coherent domain */
161 li t0, 0xff
Paul Burton90996512015-08-05 15:42:35 -0700162 sw t0, GCR_CL_COHERENCE_OFS(v1)
Paul Burton0ee958e2014-01-15 10:31:53 +0000163 ehb
164
165 /* Jump to kseg0 */
Markos Chandras81a02e32015-07-01 09:13:29 +0100166 PTR_LA t0, 1f
Paul Burton0ee958e2014-01-15 10:31:53 +0000167 jr t0
168 nop
169
Paul Burton245a7862014-04-14 12:04:27 +0100170 /*
171 * We're up, cached & coherent. Perform any further required core-level
172 * initialisation.
173 */
1741: jal mips_cps_core_init
175 nop
Paul Burton0ee958e2014-01-15 10:31:53 +0000176
Markos Chandras6521d9a2014-07-21 14:35:56 +0100177 /* Do any EVA initialization if necessary */
178 eva_init
179
Paul Burton0ee958e2014-01-15 10:31:53 +0000180 /*
Paul Burton245a7862014-04-14 12:04:27 +0100181 * Boot any other VPEs within this core that should be online, and
182 * deactivate this VPE if it should be offline.
Paul Burton0ee958e2014-01-15 10:31:53 +0000183 */
Paul Burton245a7862014-04-14 12:04:27 +0100184 jal mips_cps_boot_vpes
185 nop
Paul Burton0ee958e2014-01-15 10:31:53 +0000186
187 /* Off we go! */
Markos Chandrasb677bc02015-07-01 09:13:33 +0100188 PTR_L t1, VPEBOOTCFG_PC(v0)
189 PTR_L gp, VPEBOOTCFG_GP(v0)
190 PTR_L sp, VPEBOOTCFG_SP(v0)
Paul Burton0ee958e2014-01-15 10:31:53 +0000191 jr t1
192 nop
193 END(mips_cps_core_entry)
194
195.org 0x200
196LEAF(excep_tlbfill)
197 b .
198 nop
199 END(excep_tlbfill)
200
201.org 0x280
202LEAF(excep_xtlbfill)
203 b .
204 nop
205 END(excep_xtlbfill)
206
207.org 0x300
208LEAF(excep_cache)
209 b .
210 nop
211 END(excep_cache)
212
213.org 0x380
214LEAF(excep_genex)
215 b .
216 nop
217 END(excep_genex)
218
219.org 0x400
220LEAF(excep_intex)
221 b .
222 nop
223 END(excep_intex)
224
225.org 0x480
226LEAF(excep_ejtag)
Markos Chandras81a02e32015-07-01 09:13:29 +0100227 PTR_LA k0, ejtag_debug_handler
Paul Burton0ee958e2014-01-15 10:31:53 +0000228 jr k0
229 nop
230 END(excep_ejtag)
Paul Burton245a7862014-04-14 12:04:27 +0100231
232LEAF(mips_cps_core_init)
Paul Burton7a630762015-08-05 15:42:38 -0700233#ifdef CONFIG_MIPS_MT_SMP
Paul Burton245a7862014-04-14 12:04:27 +0100234 /* Check that the core implements the MT ASE */
235 has_mt t0, 3f
Paul Burton245a7862014-04-14 12:04:27 +0100236
237 .set push
Markos Chandras977e0432015-07-01 09:13:30 +0100238 .set mips64r2
Paul Burton245a7862014-04-14 12:04:27 +0100239 .set mt
240
241 /* Only allow 1 TC per VPE to execute... */
242 dmt
243
244 /* ...and for the moment only 1 VPE */
245 dvpe
Markos Chandras81a02e32015-07-01 09:13:29 +0100246 PTR_LA t1, 1f
Paul Burton245a7862014-04-14 12:04:27 +0100247 jr.hb t1
248 nop
249
250 /* Enter VPE configuration state */
2511: mfc0 t0, CP0_MVPCONTROL
252 ori t0, t0, MVPCONTROL_VPC
253 mtc0 t0, CP0_MVPCONTROL
254
255 /* Retrieve the number of VPEs within the core */
256 mfc0 t0, CP0_MVPCONF0
257 srl t0, t0, MVPCONF0_PVPE_SHIFT
258 andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
Markos Chandras0586ac72015-07-01 09:13:31 +0100259 addiu ta3, t0, 1
Paul Burton245a7862014-04-14 12:04:27 +0100260
261 /* If there's only 1, we're done */
262 beqz t0, 2f
263 nop
264
265 /* Loop through each VPE within this core */
Markos Chandras0586ac72015-07-01 09:13:31 +0100266 li ta1, 1
Paul Burton245a7862014-04-14 12:04:27 +0100267
2681: /* Operate on the appropriate TC */
Markos Chandras0586ac72015-07-01 09:13:31 +0100269 mtc0 ta1, CP0_VPECONTROL
Paul Burton245a7862014-04-14 12:04:27 +0100270 ehb
271
272 /* Bind TC to VPE (1:1 TC:VPE mapping) */
Markos Chandras0586ac72015-07-01 09:13:31 +0100273 mttc0 ta1, CP0_TCBIND
Paul Burton245a7862014-04-14 12:04:27 +0100274
275 /* Set exclusive TC, non-active, master */
276 li t0, VPECONF0_MVP
Markos Chandras0586ac72015-07-01 09:13:31 +0100277 sll t1, ta1, VPECONF0_XTC_SHIFT
Paul Burton245a7862014-04-14 12:04:27 +0100278 or t0, t0, t1
279 mttc0 t0, CP0_VPECONF0
280
281 /* Set TC non-active, non-allocatable */
282 mttc0 zero, CP0_TCSTATUS
283
284 /* Set TC halted */
285 li t0, TCHALT_H
286 mttc0 t0, CP0_TCHALT
287
288 /* Next VPE */
Markos Chandras0586ac72015-07-01 09:13:31 +0100289 addiu ta1, ta1, 1
290 slt t0, ta1, ta3
Paul Burton245a7862014-04-14 12:04:27 +0100291 bnez t0, 1b
292 nop
293
294 /* Leave VPE configuration state */
2952: mfc0 t0, CP0_MVPCONTROL
296 xori t0, t0, MVPCONTROL_VPC
297 mtc0 t0, CP0_MVPCONTROL
298
2993: .set pop
300#endif
301 jr ra
302 nop
303 END(mips_cps_core_init)
304
305LEAF(mips_cps_boot_vpes)
306 /* Retrieve CM base address */
Markos Chandras81a02e32015-07-01 09:13:29 +0100307 PTR_LA t0, mips_cm_base
Markos Chandrasb677bc02015-07-01 09:13:33 +0100308 PTR_L t0, 0(t0)
Paul Burton245a7862014-04-14 12:04:27 +0100309
310 /* Calculate a pointer to this cores struct core_boot_config */
Paul Burton90996512015-08-05 15:42:35 -0700311 lw t0, GCR_CL_ID_OFS(t0)
Paul Burton245a7862014-04-14 12:04:27 +0100312 li t1, COREBOOTCFG_SIZE
313 mul t0, t0, t1
Markos Chandras81a02e32015-07-01 09:13:29 +0100314 PTR_LA t1, mips_cps_core_bootcfg
Markos Chandrasb677bc02015-07-01 09:13:33 +0100315 PTR_L t1, 0(t1)
316 PTR_ADDU t0, t0, t1
Paul Burton245a7862014-04-14 12:04:27 +0100317
318 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
Paul Burton1e5fb282015-08-05 15:42:36 -0700319 li t9, 0
Paul Burton7a630762015-08-05 15:42:38 -0700320#ifdef CONFIG_MIPS_MT_SMP
Markos Chandras0586ac72015-07-01 09:13:31 +0100321 has_mt ta2, 1f
Paul Burton245a7862014-04-14 12:04:27 +0100322
323 /* Find the number of VPEs present in the core */
324 mfc0 t1, CP0_MVPCONF0
325 srl t1, t1, MVPCONF0_PVPE_SHIFT
326 andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
Markos Chandrasacac4102014-11-24 14:40:11 +0000327 addiu t1, t1, 1
Paul Burton245a7862014-04-14 12:04:27 +0100328
329 /* Calculate a mask for the VPE ID from EBase.CPUNum */
330 clz t1, t1
331 li t2, 31
332 subu t1, t2, t1
333 li t2, 1
334 sll t1, t2, t1
335 addiu t1, t1, -1
336
337 /* Retrieve the VPE ID from EBase.CPUNum */
338 mfc0 t9, $15, 1
339 and t9, t9, t1
Paul Burtona5b0f6d2015-08-05 15:42:37 -0700340#endif
Paul Burton245a7862014-04-14 12:04:27 +0100341
3421: /* Calculate a pointer to this VPEs struct vpe_boot_config */
343 li t1, VPEBOOTCFG_SIZE
344 mul v0, t9, t1
Markos Chandrasb677bc02015-07-01 09:13:33 +0100345 PTR_L ta3, COREBOOTCFG_VPECONFIG(t0)
346 PTR_ADDU v0, v0, ta3
Paul Burton245a7862014-04-14 12:04:27 +0100347
Paul Burton7a630762015-08-05 15:42:38 -0700348#ifdef CONFIG_MIPS_MT_SMP
Paul Burton245a7862014-04-14 12:04:27 +0100349
350 /* If the core doesn't support MT then return */
Markos Chandras0586ac72015-07-01 09:13:31 +0100351 bnez ta2, 1f
Paul Burton245a7862014-04-14 12:04:27 +0100352 nop
353 jr ra
354 nop
355
356 .set push
Markos Chandras977e0432015-07-01 09:13:30 +0100357 .set mips64r2
Paul Burton245a7862014-04-14 12:04:27 +0100358 .set mt
359
3601: /* Enter VPE configuration state */
361 dvpe
Markos Chandras81a02e32015-07-01 09:13:29 +0100362 PTR_LA t1, 1f
Paul Burton245a7862014-04-14 12:04:27 +0100363 jr.hb t1
364 nop
3651: mfc0 t1, CP0_MVPCONTROL
366 ori t1, t1, MVPCONTROL_VPC
367 mtc0 t1, CP0_MVPCONTROL
368 ehb
369
370 /* Loop through each VPE */
Markos Chandrasb677bc02015-07-01 09:13:33 +0100371 PTR_L ta2, COREBOOTCFG_VPEMASK(t0)
Markos Chandras0586ac72015-07-01 09:13:31 +0100372 move t8, ta2
373 li ta1, 0
Paul Burton245a7862014-04-14 12:04:27 +0100374
375 /* Check whether the VPE should be running. If not, skip it */
Markos Chandras0586ac72015-07-01 09:13:31 +01003761: andi t0, ta2, 1
Paul Burton245a7862014-04-14 12:04:27 +0100377 beqz t0, 2f
378 nop
379
380 /* Operate on the appropriate TC */
381 mfc0 t0, CP0_VPECONTROL
382 ori t0, t0, VPECONTROL_TARGTC
383 xori t0, t0, VPECONTROL_TARGTC
Markos Chandras0586ac72015-07-01 09:13:31 +0100384 or t0, t0, ta1
Paul Burton245a7862014-04-14 12:04:27 +0100385 mtc0 t0, CP0_VPECONTROL
386 ehb
387
388 /* Skip the VPE if its TC is not halted */
389 mftc0 t0, CP0_TCHALT
390 beqz t0, 2f
391 nop
392
393 /* Calculate a pointer to the VPEs struct vpe_boot_config */
394 li t0, VPEBOOTCFG_SIZE
Markos Chandras0586ac72015-07-01 09:13:31 +0100395 mul t0, t0, ta1
396 addu t0, t0, ta3
Paul Burton245a7862014-04-14 12:04:27 +0100397
398 /* Set the TC restart PC */
399 lw t1, VPEBOOTCFG_PC(t0)
400 mttc0 t1, CP0_TCRESTART
401
402 /* Set the TC stack pointer */
403 lw t1, VPEBOOTCFG_SP(t0)
404 mttgpr t1, sp
405
406 /* Set the TC global pointer */
407 lw t1, VPEBOOTCFG_GP(t0)
408 mttgpr t1, gp
409
410 /* Copy config from this VPE */
411 mfc0 t0, CP0_CONFIG
412 mttc0 t0, CP0_CONFIG
413
414 /* Ensure no software interrupts are pending */
415 mttc0 zero, CP0_CAUSE
416 mttc0 zero, CP0_STATUS
417
418 /* Set TC active, not interrupt exempt */
419 mftc0 t0, CP0_TCSTATUS
420 li t1, ~TCSTATUS_IXMT
421 and t0, t0, t1
422 ori t0, t0, TCSTATUS_A
423 mttc0 t0, CP0_TCSTATUS
424
425 /* Clear the TC halt bit */
426 mttc0 zero, CP0_TCHALT
427
428 /* Set VPE active */
429 mftc0 t0, CP0_VPECONF0
430 ori t0, t0, VPECONF0_VPA
431 mttc0 t0, CP0_VPECONF0
432
433 /* Next VPE */
Markos Chandras0586ac72015-07-01 09:13:31 +01004342: srl ta2, ta2, 1
435 addiu ta1, ta1, 1
436 bnez ta2, 1b
Paul Burton245a7862014-04-14 12:04:27 +0100437 nop
438
439 /* Leave VPE configuration state */
440 mfc0 t1, CP0_MVPCONTROL
441 xori t1, t1, MVPCONTROL_VPC
442 mtc0 t1, CP0_MVPCONTROL
443 ehb
444 evpe
445
446 /* Check whether this VPE is meant to be running */
447 li t0, 1
448 sll t0, t0, t9
449 and t0, t0, t8
450 bnez t0, 2f
451 nop
452
453 /* This VPE should be offline, halt the TC */
454 li t0, TCHALT_H
455 mtc0 t0, CP0_TCHALT
Markos Chandras81a02e32015-07-01 09:13:29 +0100456 PTR_LA t0, 1f
Paul Burton245a7862014-04-14 12:04:27 +01004571: jr.hb t0
458 nop
459
4602: .set pop
461
Paul Burton7a630762015-08-05 15:42:38 -0700462#endif /* CONFIG_MIPS_MT_SMP */
Paul Burton245a7862014-04-14 12:04:27 +0100463
464 /* Return */
465 jr ra
466 nop
467 END(mips_cps_boot_vpes)
Paul Burton3179d372014-04-14 11:00:56 +0100468
469#if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
470
471 /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
472 .macro psstate dest
473 .set push
474 .set noat
475 lw $1, TI_CPU(gp)
476 sll $1, $1, LONGLOG
Markos Chandras81a02e32015-07-01 09:13:29 +0100477 PTR_LA \dest, __per_cpu_offset
Paul Burton3179d372014-04-14 11:00:56 +0100478 addu $1, $1, \dest
479 lw $1, 0($1)
Markos Chandras81a02e32015-07-01 09:13:29 +0100480 PTR_LA \dest, cps_cpu_state
Paul Burton3179d372014-04-14 11:00:56 +0100481 addu \dest, \dest, $1
482 .set pop
483 .endm
484
485LEAF(mips_cps_pm_save)
486 /* Save CPU state */
487 SUSPEND_SAVE_REGS
488 psstate t1
489 SUSPEND_SAVE_STATIC
490 jr v0
491 nop
492 END(mips_cps_pm_save)
493
494LEAF(mips_cps_pm_restore)
495 /* Restore CPU state */
496 psstate t1
497 RESUME_RESTORE_STATIC
498 RESUME_RESTORE_REGS_RETURN
499 END(mips_cps_pm_restore)
500
501#endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */