2 * Copyright (C) 2013 Imagination Technologies
3 * Author: Paul Burton <paul.burton@imgtec.com>
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.
11 #include <asm/addrspace.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/asmmacro.h>
15 #include <asm/cacheops.h>
17 #include <asm/mipsregs.h>
18 #include <asm/mipsmtregs.h>
21 #define GCR_CL_COHERENCE_OFS 0x2008
22 #define GCR_CL_ID_OFS 0x2028
29 # define STATUS_BITDEPS ST0_KX
31 # define STATUS_BITDEPS 0
34 #ifdef CONFIG_MIPS_CPS_NS16550
36 #define DUMP_EXCEP(name) \
38 jal mips_cps_bev_dump; \
42 #else /* !CONFIG_MIPS_CPS_NS16550 */
44 #define DUMP_EXCEP(name)
46 #endif /* !CONFIG_MIPS_CPS_NS16550 */
49 * Set dest to non-zero if the core supports the MT ASE, else zero. If
50 * MT is not supported then branch to nomt.
52 .macro has_mt dest, nomt
53 mfc0 \dest, CP0_CONFIG, 1
55 mfc0 \dest, CP0_CONFIG, 2
57 mfc0 \dest, CP0_CONFIG, 3
58 andi \dest, \dest, MIPS_CONF3_MT
63 /* Calculate an uncached address for the CM GCRs */
67 MFC0 $1, CP0_CMGCRBASE
69 PTR_LI \dest, UNCAC_BASE
70 PTR_ADDU \dest, \dest, $1
74 .section .text.cps-vec
77 LEAF(mips_cps_core_entry)
79 * These first 4 bytes will be patched by cps_smp_setup to load the
80 * CCA to use into register s0.
84 /* Check whether we're here due to an NMI */
91 PTR_LA k0, nmi_handler
101 li t0, ST0_CU1 | ST0_CU0 | ST0_BEV | STATUS_BITDEPS
104 /* Initialize the L1 caches */
105 jal mips_cps_cache_init
108 /* Set Kseg0 CCA to that in s0 */
116 /* Enter the coherent domain */
119 sw t0, GCR_CL_COHERENCE_OFS(v1)
128 * We're up, cached & coherent. Perform any further required core-level
131 1: jal mips_cps_core_init
134 /* Do any EVA initialization if necessary */
137 /* Retrieve boot configuration pointers */
138 jal mips_cps_get_bootcfg
142 * Boot any other VPEs within this core that should be online, and
143 * deactivate this VPE if it should be offline.
146 jal mips_cps_boot_vpes
150 PTR_L t1, VPEBOOTCFG_PC(v1)
151 PTR_L gp, VPEBOOTCFG_GP(v1)
152 PTR_L sp, VPEBOOTCFG_SP(v1)
155 END(mips_cps_core_entry)
159 DUMP_EXCEP("TLB Fill")
166 DUMP_EXCEP("XTLB Fill")
180 DUMP_EXCEP("General")
187 DUMP_EXCEP("Interrupt")
195 PTR_LA k0, ejtag_debug_handler
200 LEAF(mips_cps_core_init)
201 #ifdef CONFIG_MIPS_MT_SMP
202 /* Check that the core implements the MT ASE */
208 /* Only allow 1 TC per VPE to execute... */
211 /* ...and for the moment only 1 VPE */
217 /* Enter VPE configuration state */
218 1: mfc0 t0, CP0_MVPCONTROL
219 ori t0, t0, MVPCONTROL_VPC
220 mtc0 t0, CP0_MVPCONTROL
222 /* Retrieve the number of VPEs within the core */
223 mfc0 t0, CP0_MVPCONF0
224 srl t0, t0, MVPCONF0_PVPE_SHIFT
225 andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
228 /* If there's only 1, we're done */
232 /* Loop through each VPE within this core */
235 1: /* Operate on the appropriate TC */
236 mtc0 ta1, CP0_VPECONTROL
239 /* Bind TC to VPE (1:1 TC:VPE mapping) */
240 mttc0 ta1, CP0_TCBIND
242 /* Set exclusive TC, non-active, master */
244 sll t1, ta1, VPECONF0_XTC_SHIFT
246 mttc0 t0, CP0_VPECONF0
248 /* Set TC non-active, non-allocatable */
249 mttc0 zero, CP0_TCSTATUS
261 /* Leave VPE configuration state */
262 2: mfc0 t0, CP0_MVPCONTROL
263 xori t0, t0, MVPCONTROL_VPC
264 mtc0 t0, CP0_MVPCONTROL
270 END(mips_cps_core_init)
273 * mips_cps_get_bootcfg() - retrieve boot configuration pointers
275 * Returns: pointer to struct core_boot_config in v0, pointer to
276 * struct vpe_boot_config in v1, VPE ID in t9
278 LEAF(mips_cps_get_bootcfg)
279 /* Calculate a pointer to this cores struct core_boot_config */
281 lw t0, GCR_CL_ID_OFS(t0)
282 li t1, COREBOOTCFG_SIZE
284 PTR_LA t1, mips_cps_core_bootcfg
288 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
290 #ifdef CONFIG_MIPS_MT_SMP
293 /* Find the number of VPEs present in the core */
294 mfc0 t1, CP0_MVPCONF0
295 srl t1, t1, MVPCONF0_PVPE_SHIFT
296 andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
299 /* Calculate a mask for the VPE ID from EBase.CPUNum */
307 /* Retrieve the VPE ID from EBase.CPUNum */
312 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
313 li t1, VPEBOOTCFG_SIZE
315 PTR_L ta3, COREBOOTCFG_VPECONFIG(v0)
320 END(mips_cps_get_bootcfg)
322 LEAF(mips_cps_boot_vpes)
323 PTR_L ta2, COREBOOTCFG_VPEMASK(a0)
324 PTR_L ta3, COREBOOTCFG_VPECONFIG(a0)
326 #ifdef CONFIG_MIPS_MT
331 /* If the core doesn't support MT then return */
334 /* Enter VPE configuration state */
339 1: mfc0 t1, CP0_MVPCONTROL
340 ori t1, t1, MVPCONTROL_VPC
341 mtc0 t1, CP0_MVPCONTROL
344 /* Loop through each VPE */
348 /* Check whether the VPE should be running. If not, skip it */
353 /* Operate on the appropriate TC */
354 mfc0 t0, CP0_VPECONTROL
355 ori t0, t0, VPECONTROL_TARGTC
356 xori t0, t0, VPECONTROL_TARGTC
358 mtc0 t0, CP0_VPECONTROL
361 /* Skip the VPE if its TC is not halted */
366 /* Calculate a pointer to the VPEs struct vpe_boot_config */
367 li t0, VPEBOOTCFG_SIZE
371 /* Set the TC restart PC */
372 lw t1, VPEBOOTCFG_PC(t0)
373 mttc0 t1, CP0_TCRESTART
375 /* Set the TC stack pointer */
376 lw t1, VPEBOOTCFG_SP(t0)
379 /* Set the TC global pointer */
380 lw t1, VPEBOOTCFG_GP(t0)
383 /* Copy config from this VPE */
387 /* Ensure no software interrupts are pending */
388 mttc0 zero, CP0_CAUSE
389 mttc0 zero, CP0_STATUS
391 /* Set TC active, not interrupt exempt */
392 mftc0 t0, CP0_TCSTATUS
393 li t1, ~TCSTATUS_IXMT
395 ori t0, t0, TCSTATUS_A
396 mttc0 t0, CP0_TCSTATUS
398 /* Clear the TC halt bit */
399 mttc0 zero, CP0_TCHALT
402 mftc0 t0, CP0_VPECONF0
403 ori t0, t0, VPECONF0_VPA
404 mttc0 t0, CP0_VPECONF0
412 /* Leave VPE configuration state */
413 mfc0 t1, CP0_MVPCONTROL
414 xori t1, t1, MVPCONTROL_VPC
415 mtc0 t1, CP0_MVPCONTROL
419 /* Check whether this VPE is meant to be running */
426 /* This VPE should be offline, halt the TC */
435 #endif /* CONFIG_MIPS_MT_SMP */
440 END(mips_cps_boot_vpes)
442 LEAF(mips_cps_cache_init)
444 * Clear the bits used to index the caches. Note that the architecture
445 * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
446 * be valid for all MIPS32 CPUs, even those for which said writes are
449 mtc0 zero, CP0_TAGLO, 0
450 mtc0 zero, CP0_TAGHI, 0
451 mtc0 zero, CP0_TAGLO, 2
452 mtc0 zero, CP0_TAGHI, 2
455 /* Primary cache configuration is indicated by Config1 */
456 mfc0 v0, CP0_CONFIG, 1
458 /* Detect I-cache line size */
459 _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
464 /* Detect I-cache size */
465 _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
471 1: /* At this point t1 == I-cache sets per way */
472 _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
479 1: cache Index_Store_Tag_I, 0(a0)
485 /* Detect D-cache line size */
486 _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
491 /* Detect D-cache size */
492 _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
498 1: /* At this point t1 == D-cache sets per way */
499 _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
507 1: cache Index_Store_Tag_D, 0(a0)
514 END(mips_cps_cache_init)
516 #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
518 /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
524 PTR_LA \dest, __per_cpu_offset
527 PTR_LA \dest, cps_cpu_state
528 addu \dest, \dest, $1
532 LEAF(mips_cps_pm_save)
539 END(mips_cps_pm_save)
541 LEAF(mips_cps_pm_restore)
542 /* Restore CPU state */
544 RESUME_RESTORE_STATIC
545 RESUME_RESTORE_REGS_RETURN
546 END(mips_cps_pm_restore)
548 #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */