1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2013 Imagination Technologies
4 * Author: Paul Burton <paul.burton@mips.com>
7 #include <linux/init.h>
8 #include <asm/addrspace.h>
10 #include <asm/asm-offsets.h>
11 #include <asm/asmmacro.h>
12 #include <asm/cacheops.h>
14 #include <asm/mipsregs.h>
15 #include <asm/mipsmtregs.h>
17 #include <asm/smp-cps.h>
19 #define GCR_CPC_BASE_OFS 0x0088
20 #define GCR_CL_COHERENCE_OFS 0x2008
21 #define GCR_CL_ID_OFS 0x2028
23 #define CPC_CL_VC_STOP_OFS 0x2020
24 #define CPC_CL_VC_RUN_OFS 0x2028
31 # define STATUS_BITDEPS ST0_KX
33 # define STATUS_BITDEPS 0
36 #ifdef CONFIG_MIPS_CPS_NS16550
38 #define DUMP_EXCEP(name) \
40 jal mips_cps_bev_dump; \
44 #else /* !CONFIG_MIPS_CPS_NS16550 */
46 #define DUMP_EXCEP(name)
48 #endif /* !CONFIG_MIPS_CPS_NS16550 */
51 * Set dest to non-zero if the core supports the MT ASE, else zero. If
52 * MT is not supported then branch to nomt.
54 .macro has_mt dest, nomt
55 mfc0 \dest, CP0_CONFIG, 1
57 mfc0 \dest, CP0_CONFIG, 2
59 mfc0 \dest, CP0_CONFIG, 3
60 andi \dest, \dest, MIPS_CONF3_MT
66 * Set dest to non-zero if the core supports MIPSr6 multithreading
67 * (ie. VPs), else zero. If MIPSr6 multithreading is not supported then
70 .macro has_vp dest, nomt
71 mfc0 \dest, CP0_CONFIG, 1
73 mfc0 \dest, CP0_CONFIG, 2
75 mfc0 \dest, CP0_CONFIG, 3
77 mfc0 \dest, CP0_CONFIG, 4
79 mfc0 \dest, CP0_CONFIG, 5
80 andi \dest, \dest, MIPS_CONF5_VP
86 LEAF(mips_cps_core_boot)
87 /* Save CCA and GCR base */
91 /* We don't know how to do coherence setup on earlier ISA */
93 /* Skip cache & coherence setup if we're already coherent */
94 lw s7, GCR_CL_COHERENCE_OFS(s1)
98 /* Initialize the L1 caches */
99 jal mips_cps_cache_init
102 /* Enter the coherent domain */
104 sw t0, GCR_CL_COHERENCE_OFS(s1)
106 #endif /* MIPS_ISA_REV > 0 */
108 /* Set Kseg0 CCA to that in s0 */
109 1: mfc0 t0, CP0_CONFIG
122 * We're up, cached & coherent. Perform any EVA initialization necessary
123 * before we access memory.
127 /* Retrieve boot configuration pointers */
128 jal mips_cps_get_bootcfg
131 /* Skip core-level init if we started up coherent */
135 /* Perform any further required core-level initialisation */
136 jal mips_cps_core_init
140 * Boot any other VPEs within this core that should be online, and
141 * deactivate this VPE if it should be offline.
144 jal mips_cps_boot_vpes
148 1: PTR_L t1, VPEBOOTCFG_PC(v1)
149 PTR_L gp, VPEBOOTCFG_GP(v1)
150 PTR_L sp, VPEBOOTCFG_SP(v1)
153 END(mips_cps_core_boot)
157 DUMP_EXCEP("TLB Fill")
163 DUMP_EXCEP("XTLB Fill")
175 DUMP_EXCEP("General")
181 DUMP_EXCEP("Interrupt")
187 PTR_LA k0, ejtag_debug_handler
193 LEAF(mips_cps_core_init)
194 #ifdef CONFIG_MIPS_MT_SMP
195 /* Check that the core implements the MT ASE */
199 .set MIPS_ISA_LEVEL_RAW
202 /* Only allow 1 TC per VPE to execute... */
205 /* ...and for the moment only 1 VPE */
211 /* Enter VPE configuration state */
212 1: mfc0 t0, CP0_MVPCONTROL
213 ori t0, t0, MVPCONTROL_VPC
214 mtc0 t0, CP0_MVPCONTROL
216 /* Retrieve the number of VPEs within the core */
217 mfc0 t0, CP0_MVPCONF0
218 srl t0, t0, MVPCONF0_PVPE_SHIFT
219 andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
222 /* If there's only 1, we're done */
226 /* Loop through each VPE within this core */
229 1: /* Operate on the appropriate TC */
230 mtc0 ta1, CP0_VPECONTROL
233 /* Bind TC to VPE (1:1 TC:VPE mapping) */
234 mttc0 ta1, CP0_TCBIND
236 /* Set exclusive TC, non-active, master */
238 sll t1, ta1, VPECONF0_XTC_SHIFT
240 mttc0 t0, CP0_VPECONF0
242 /* Set TC non-active, non-allocatable */
243 mttc0 zero, CP0_TCSTATUS
255 /* Leave VPE configuration state */
256 2: mfc0 t0, CP0_MVPCONTROL
257 xori t0, t0, MVPCONTROL_VPC
258 mtc0 t0, CP0_MVPCONTROL
264 END(mips_cps_core_init)
267 * mips_cps_get_bootcfg() - retrieve boot configuration pointers
269 * Returns: pointer to struct core_boot_config in v0, pointer to
270 * struct vpe_boot_config in v1, VPE ID in t9
272 LEAF(mips_cps_get_bootcfg)
273 /* Calculate a pointer to this cores struct core_boot_config */
274 lw t0, GCR_CL_ID_OFS(s1)
275 li t1, COREBOOTCFG_SIZE
277 PTR_LA t1, mips_cps_core_bootcfg
281 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
283 #if defined(CONFIG_CPU_MIPSR6)
287 * Assume non-contiguous numbering. Perhaps some day we'll need
288 * to handle contiguous VP numbering, but no such systems yet
291 mfc0 t9, CP0_GLOBALNUMBER
292 andi t9, t9, MIPS_GLOBALNUMBER_VP
293 #elif defined(CONFIG_MIPS_MT_SMP)
296 /* Find the number of VPEs present in the core */
297 mfc0 t1, CP0_MVPCONF0
298 srl t1, t1, MVPCONF0_PVPE_SHIFT
299 andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
302 /* Calculate a mask for the VPE ID from EBase.CPUNum */
310 /* Retrieve the VPE ID from EBase.CPUNum */
315 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
316 li t1, VPEBOOTCFG_SIZE
318 PTR_L ta3, COREBOOTCFG_VPECONFIG(v0)
323 END(mips_cps_get_bootcfg)
325 LEAF(mips_cps_boot_vpes)
326 lw ta2, COREBOOTCFG_VPEMASK(a0)
327 PTR_L ta3, COREBOOTCFG_VPECONFIG(a0)
329 #if defined(CONFIG_CPU_MIPSR6)
333 /* Find base address of CPC */
334 PTR_LA t1, mips_gcr_base
336 PTR_L t1, GCR_CPC_BASE_OFS(t1)
339 PTR_LI t2, UNCAC_BASE
342 /* Start any other VPs that ought to be running */
343 PTR_S ta2, CPC_CL_VC_RUN_OFS(t1)
345 /* Ensure this VP stops running if it shouldn't be */
347 PTR_S ta2, CPC_CL_VC_STOP_OFS(t1)
350 #elif defined(CONFIG_MIPS_MT)
352 /* If the core doesn't support MT then return */
355 /* Enter VPE configuration state */
357 .set MIPS_ISA_LEVEL_RAW
365 1: mfc0 t1, CP0_MVPCONTROL
366 ori t1, t1, MVPCONTROL_VPC
367 mtc0 t1, CP0_MVPCONTROL
370 /* Loop through each VPE */
374 /* Check whether the VPE should be running. If not, skip it */
379 /* Operate on the appropriate TC */
380 mfc0 t0, CP0_VPECONTROL
381 ori t0, t0, VPECONTROL_TARGTC
382 xori t0, t0, VPECONTROL_TARGTC
384 mtc0 t0, CP0_VPECONTROL
388 .set MIPS_ISA_LEVEL_RAW
391 /* Skip the VPE if its TC is not halted */
396 /* Calculate a pointer to the VPEs struct vpe_boot_config */
397 li t0, VPEBOOTCFG_SIZE
401 /* Set the TC restart PC */
402 lw t1, VPEBOOTCFG_PC(t0)
403 mttc0 t1, CP0_TCRESTART
405 /* Set the TC stack pointer */
406 lw t1, VPEBOOTCFG_SP(t0)
409 /* Set the TC global pointer */
410 lw t1, VPEBOOTCFG_GP(t0)
413 /* Copy config from this VPE */
418 * Copy the EVA config from this VPE if the CPU supports it.
419 * CONFIG3 must exist to be running MT startup - just read it.
421 mfc0 t0, CP0_CONFIG, 3
422 and t0, t0, MIPS_CONF3_SC
426 mttc0 t0, CP0_SEGCTL0
428 mttc0 t0, CP0_SEGCTL1
430 mttc0 t0, CP0_SEGCTL2
432 /* Ensure no software interrupts are pending */
433 mttc0 zero, CP0_CAUSE
434 mttc0 zero, CP0_STATUS
436 /* Set TC active, not interrupt exempt */
437 mftc0 t0, CP0_TCSTATUS
438 li t1, ~TCSTATUS_IXMT
440 ori t0, t0, TCSTATUS_A
441 mttc0 t0, CP0_TCSTATUS
443 /* Clear the TC halt bit */
444 mttc0 zero, CP0_TCHALT
447 mftc0 t0, CP0_VPECONF0
448 ori t0, t0, VPECONF0_VPA
449 mttc0 t0, CP0_VPECONF0
457 /* Leave VPE configuration state */
458 mfc0 t1, CP0_MVPCONTROL
459 xori t1, t1, MVPCONTROL_VPC
460 mtc0 t1, CP0_MVPCONTROL
466 /* Check whether this VPE is meant to be running */
473 /* This VPE should be offline, halt the TC */
482 #endif /* CONFIG_MIPS_MT_SMP */
487 END(mips_cps_boot_vpes)
490 LEAF(mips_cps_cache_init)
492 * Clear the bits used to index the caches. Note that the architecture
493 * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
494 * be valid for all MIPS32 CPUs, even those for which said writes are
497 mtc0 zero, CP0_TAGLO, 0
498 mtc0 zero, CP0_TAGHI, 0
499 mtc0 zero, CP0_TAGLO, 2
500 mtc0 zero, CP0_TAGHI, 2
503 /* Primary cache configuration is indicated by Config1 */
504 mfc0 v0, CP0_CONFIG, 1
506 /* Detect I-cache line size */
507 _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
512 /* Detect I-cache size */
513 _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
519 1: /* At this point t1 == I-cache sets per way */
520 _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
527 1: cache Index_Store_Tag_I, 0(a0)
533 /* Detect D-cache line size */
534 _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
539 /* Detect D-cache size */
540 _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
546 1: /* At this point t1 == D-cache sets per way */
547 _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
555 1: cache Index_Store_Tag_D, 0(a0)
562 END(mips_cps_cache_init)
563 #endif /* MIPS_ISA_REV > 0 */
565 #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
567 /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
573 PTR_LA \dest, __per_cpu_offset
574 PTR_ADDU $1, $1, \dest
576 PTR_LA \dest, cps_cpu_state
577 PTR_ADDU \dest, \dest, $1
581 LEAF(mips_cps_pm_save)
588 END(mips_cps_pm_save)
590 LEAF(mips_cps_pm_restore)
591 /* Restore CPU state */
593 RESUME_RESTORE_STATIC
594 RESUME_RESTORE_REGS_RETURN
595 END(mips_cps_pm_restore)
597 #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */