1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2013 Imagination Technologies
7 #include <asm/addrspace.h>
9 #include <asm/asm-offsets.h>
10 #include <asm/asmmacro.h>
11 #include <asm/cacheops.h>
13 #include <asm/mipsregs.h>
14 #include <asm/mipsmtregs.h>
16 #include <asm/smp-cps.h>
18 #define GCR_CPC_BASE_OFS 0x0088
19 #define GCR_CL_COHERENCE_OFS 0x2008
20 #define GCR_CL_ID_OFS 0x2028
22 #define CPC_CL_VC_STOP_OFS 0x2020
23 #define CPC_CL_VC_RUN_OFS 0x2028
30 # define STATUS_BITDEPS ST0_KX
32 # define STATUS_BITDEPS 0
35 #ifdef CONFIG_MIPS_CPS_NS16550
37 #define DUMP_EXCEP(name) \
39 jal mips_cps_bev_dump; \
43 #else /* !CONFIG_MIPS_CPS_NS16550 */
45 #define DUMP_EXCEP(name)
47 #endif /* !CONFIG_MIPS_CPS_NS16550 */
50 * Set dest to non-zero if the core supports the MT ASE, else zero. If
51 * MT is not supported then branch to nomt.
53 .macro has_mt dest, nomt
54 mfc0 \dest, CP0_CONFIG, 1
56 mfc0 \dest, CP0_CONFIG, 2
58 mfc0 \dest, CP0_CONFIG, 3
59 andi \dest, \dest, MIPS_CONF3_MT
65 * Set dest to non-zero if the core supports MIPSr6 multithreading
66 * (ie. VPs), else zero. If MIPSr6 multithreading is not supported then
69 .macro has_vp dest, nomt
70 mfc0 \dest, CP0_CONFIG, 1
72 mfc0 \dest, CP0_CONFIG, 2
74 mfc0 \dest, CP0_CONFIG, 3
76 mfc0 \dest, CP0_CONFIG, 4
78 mfc0 \dest, CP0_CONFIG, 5
79 andi \dest, \dest, MIPS_CONF5_VP
87 LEAF(mips_cps_core_entry)
89 * These first several instructions will be patched by cps_smp_setup to load the
90 * CCA to use into register s0 and GCR base address to register s1.
92 .rept CPS_ENTRY_PATCH_INSNS
96 .global mips_cps_core_entry_patch_end
97 mips_cps_core_entry_patch_end:
99 /* Check whether we're here due to an NMI */
106 PTR_LA k0, nmi_handler
116 li t0, ST0_CU1 | ST0_CU0 | ST0_BEV | STATUS_BITDEPS
119 /* We don't know how to do coherence setup on earlier ISA */
121 /* Skip cache & coherence setup if we're already coherent */
122 lw s7, GCR_CL_COHERENCE_OFS(s1)
126 /* Initialize the L1 caches */
127 jal mips_cps_cache_init
130 /* Enter the coherent domain */
132 sw t0, GCR_CL_COHERENCE_OFS(s1)
134 #endif /* MIPS_ISA_REV > 0 */
136 /* Set Kseg0 CCA to that in s0 */
137 1: mfc0 t0, CP0_CONFIG
150 * We're up, cached & coherent. Perform any EVA initialization necessary
151 * before we access memory.
155 /* Retrieve boot configuration pointers */
156 jal mips_cps_get_bootcfg
159 /* Skip core-level init if we started up coherent */
163 /* Perform any further required core-level initialisation */
164 jal mips_cps_core_init
168 * Boot any other VPEs within this core that should be online, and
169 * deactivate this VPE if it should be offline.
172 jal mips_cps_boot_vpes
176 1: PTR_L t1, VPEBOOTCFG_PC(v1)
177 PTR_L gp, VPEBOOTCFG_GP(v1)
178 PTR_L sp, VPEBOOTCFG_SP(v1)
181 END(mips_cps_core_entry)
185 DUMP_EXCEP("TLB Fill")
192 DUMP_EXCEP("XTLB Fill")
206 DUMP_EXCEP("General")
213 DUMP_EXCEP("Interrupt")
220 PTR_LA k0, ejtag_debug_handler
225 LEAF(mips_cps_core_init)
226 #ifdef CONFIG_MIPS_MT_SMP
227 /* Check that the core implements the MT ASE */
231 .set MIPS_ISA_LEVEL_RAW
234 /* Only allow 1 TC per VPE to execute... */
237 /* ...and for the moment only 1 VPE */
243 /* Enter VPE configuration state */
244 1: mfc0 t0, CP0_MVPCONTROL
245 ori t0, t0, MVPCONTROL_VPC
246 mtc0 t0, CP0_MVPCONTROL
248 /* Retrieve the number of VPEs within the core */
249 mfc0 t0, CP0_MVPCONF0
250 srl t0, t0, MVPCONF0_PVPE_SHIFT
251 andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
254 /* If there's only 1, we're done */
258 /* Loop through each VPE within this core */
261 1: /* Operate on the appropriate TC */
262 mtc0 ta1, CP0_VPECONTROL
265 /* Bind TC to VPE (1:1 TC:VPE mapping) */
266 mttc0 ta1, CP0_TCBIND
268 /* Set exclusive TC, non-active, master */
270 sll t1, ta1, VPECONF0_XTC_SHIFT
272 mttc0 t0, CP0_VPECONF0
274 /* Set TC non-active, non-allocatable */
275 mttc0 zero, CP0_TCSTATUS
287 /* Leave VPE configuration state */
288 2: mfc0 t0, CP0_MVPCONTROL
289 xori t0, t0, MVPCONTROL_VPC
290 mtc0 t0, CP0_MVPCONTROL
296 END(mips_cps_core_init)
299 * mips_cps_get_bootcfg() - retrieve boot configuration pointers
301 * Returns: pointer to struct core_boot_config in v0, pointer to
302 * struct vpe_boot_config in v1, VPE ID in t9
304 LEAF(mips_cps_get_bootcfg)
305 /* Calculate a pointer to this cores struct core_boot_config */
306 lw t0, GCR_CL_ID_OFS(s1)
307 li t1, COREBOOTCFG_SIZE
309 PTR_LA t1, mips_cps_core_bootcfg
313 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
315 #if defined(CONFIG_CPU_MIPSR6)
319 * Assume non-contiguous numbering. Perhaps some day we'll need
320 * to handle contiguous VP numbering, but no such systems yet
323 mfc0 t9, CP0_GLOBALNUMBER
324 andi t9, t9, MIPS_GLOBALNUMBER_VP
325 #elif defined(CONFIG_MIPS_MT_SMP)
328 /* Find the number of VPEs present in the core */
329 mfc0 t1, CP0_MVPCONF0
330 srl t1, t1, MVPCONF0_PVPE_SHIFT
331 andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
334 /* Calculate a mask for the VPE ID from EBase.CPUNum */
342 /* Retrieve the VPE ID from EBase.CPUNum */
347 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
348 li t1, VPEBOOTCFG_SIZE
350 PTR_L ta3, COREBOOTCFG_VPECONFIG(v0)
355 END(mips_cps_get_bootcfg)
357 LEAF(mips_cps_boot_vpes)
358 lw ta2, COREBOOTCFG_VPEMASK(a0)
359 PTR_L ta3, COREBOOTCFG_VPECONFIG(a0)
361 #if defined(CONFIG_CPU_MIPSR6)
365 /* Find base address of CPC */
366 PTR_LA t1, mips_gcr_base
368 PTR_L t1, GCR_CPC_BASE_OFS(t1)
371 PTR_LI t2, UNCAC_BASE
374 /* Start any other VPs that ought to be running */
375 PTR_S ta2, CPC_CL_VC_RUN_OFS(t1)
377 /* Ensure this VP stops running if it shouldn't be */
379 PTR_S ta2, CPC_CL_VC_STOP_OFS(t1)
382 #elif defined(CONFIG_MIPS_MT)
384 /* If the core doesn't support MT then return */
387 /* Enter VPE configuration state */
389 .set MIPS_ISA_LEVEL_RAW
397 1: mfc0 t1, CP0_MVPCONTROL
398 ori t1, t1, MVPCONTROL_VPC
399 mtc0 t1, CP0_MVPCONTROL
402 /* Loop through each VPE */
406 /* Check whether the VPE should be running. If not, skip it */
411 /* Operate on the appropriate TC */
412 mfc0 t0, CP0_VPECONTROL
413 ori t0, t0, VPECONTROL_TARGTC
414 xori t0, t0, VPECONTROL_TARGTC
416 mtc0 t0, CP0_VPECONTROL
420 .set MIPS_ISA_LEVEL_RAW
423 /* Skip the VPE if its TC is not halted */
428 /* Calculate a pointer to the VPEs struct vpe_boot_config */
429 li t0, VPEBOOTCFG_SIZE
433 /* Set the TC restart PC */
434 lw t1, VPEBOOTCFG_PC(t0)
435 mttc0 t1, CP0_TCRESTART
437 /* Set the TC stack pointer */
438 lw t1, VPEBOOTCFG_SP(t0)
441 /* Set the TC global pointer */
442 lw t1, VPEBOOTCFG_GP(t0)
445 /* Copy config from this VPE */
450 * Copy the EVA config from this VPE if the CPU supports it.
451 * CONFIG3 must exist to be running MT startup - just read it.
453 mfc0 t0, CP0_CONFIG, 3
454 and t0, t0, MIPS_CONF3_SC
458 mttc0 t0, CP0_SEGCTL0
460 mttc0 t0, CP0_SEGCTL1
462 mttc0 t0, CP0_SEGCTL2
464 /* Ensure no software interrupts are pending */
465 mttc0 zero, CP0_CAUSE
466 mttc0 zero, CP0_STATUS
468 /* Set TC active, not interrupt exempt */
469 mftc0 t0, CP0_TCSTATUS
470 li t1, ~TCSTATUS_IXMT
472 ori t0, t0, TCSTATUS_A
473 mttc0 t0, CP0_TCSTATUS
475 /* Clear the TC halt bit */
476 mttc0 zero, CP0_TCHALT
479 mftc0 t0, CP0_VPECONF0
480 ori t0, t0, VPECONF0_VPA
481 mttc0 t0, CP0_VPECONF0
489 /* Leave VPE configuration state */
490 mfc0 t1, CP0_MVPCONTROL
491 xori t1, t1, MVPCONTROL_VPC
492 mtc0 t1, CP0_MVPCONTROL
498 /* Check whether this VPE is meant to be running */
505 /* This VPE should be offline, halt the TC */
514 #endif /* CONFIG_MIPS_MT_SMP */
519 END(mips_cps_boot_vpes)
522 LEAF(mips_cps_cache_init)
524 * Clear the bits used to index the caches. Note that the architecture
525 * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
526 * be valid for all MIPS32 CPUs, even those for which said writes are
529 mtc0 zero, CP0_TAGLO, 0
530 mtc0 zero, CP0_TAGHI, 0
531 mtc0 zero, CP0_TAGLO, 2
532 mtc0 zero, CP0_TAGHI, 2
535 /* Primary cache configuration is indicated by Config1 */
536 mfc0 v0, CP0_CONFIG, 1
538 /* Detect I-cache line size */
539 _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
544 /* Detect I-cache size */
545 _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
551 1: /* At this point t1 == I-cache sets per way */
552 _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
559 1: cache Index_Store_Tag_I, 0(a0)
565 /* Detect D-cache line size */
566 _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
571 /* Detect D-cache size */
572 _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
578 1: /* At this point t1 == D-cache sets per way */
579 _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
587 1: cache Index_Store_Tag_D, 0(a0)
594 END(mips_cps_cache_init)
595 #endif /* MIPS_ISA_REV > 0 */
597 #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
599 /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
605 PTR_LA \dest, __per_cpu_offset
608 PTR_LA \dest, cps_cpu_state
609 addu \dest, \dest, $1
613 LEAF(mips_cps_pm_save)
620 END(mips_cps_pm_save)
622 LEAF(mips_cps_pm_restore)
623 /* Restore CPU state */
625 RESUME_RESTORE_STATIC
626 RESUME_RESTORE_REGS_RETURN
627 END(mips_cps_pm_restore)
629 #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */