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>
16 #include <asm/mipsregs.h>
17 #include <asm/mipsmtregs.h>
20 #define GCR_CL_COHERENCE_OFS 0x2008
21 #define GCR_CL_ID_OFS 0x2028
28 * Set dest to non-zero if the core supports the MT ASE, else zero. If
29 * MT is not supported then branch to nomt.
31 .macro has_mt dest, nomt
32 mfc0 \dest, CP0_CONFIG
34 mfc0 \dest, CP0_CONFIG, 1
36 mfc0 \dest, CP0_CONFIG, 2
38 mfc0 \dest, CP0_CONFIG, 3
39 andi \dest, \dest, MIPS_CONF3_MT
43 .section .text.cps-vec
46 LEAF(mips_cps_core_entry)
48 * These first 8 bytes will be patched by cps_smp_setup to load the
49 * base address of the CM GCRs into register v1.
53 /* Check whether we're here due to an NMI */
70 li t0, ST0_CU1 | ST0_CU0
74 * Clear the bits used to index the caches. Note that the architecture
75 * dictates that writing to any of TagLo or TagHi selects 0 or 2 should
76 * be valid for all MIPS32 CPUs, even those for which said writes are
79 mtc0 zero, CP0_TAGLO, 0
80 mtc0 zero, CP0_TAGHI, 0
81 mtc0 zero, CP0_TAGLO, 2
82 mtc0 zero, CP0_TAGHI, 2
85 /* Primary cache configuration is indicated by Config1 */
86 mfc0 v0, CP0_CONFIG, 1
88 /* Detect I-cache line size */
89 _EXT t0, v0, MIPS_CONF1_IL_SHF, MIPS_CONF1_IL_SZ
94 /* Detect I-cache size */
95 _EXT t1, v0, MIPS_CONF1_IS_SHF, MIPS_CONF1_IS_SZ
101 1: /* At this point t1 == I-cache sets per way */
102 _EXT t2, v0, MIPS_CONF1_IA_SHF, MIPS_CONF1_IA_SZ
109 1: cache Index_Store_Tag_I, 0(a0)
115 /* Detect D-cache line size */
116 _EXT t0, v0, MIPS_CONF1_DL_SHF, MIPS_CONF1_DL_SZ
121 /* Detect D-cache size */
122 _EXT t1, v0, MIPS_CONF1_DS_SHF, MIPS_CONF1_DS_SZ
128 1: /* At this point t1 == D-cache sets per way */
129 _EXT t2, v0, MIPS_CONF1_DA_SHF, MIPS_CONF1_DA_SZ
137 1: cache Index_Store_Tag_D, 0(a0)
142 /* Set Kseg0 cacheable, coherent, write-back, write-allocate */
149 /* Enter the coherent domain */
151 sw t0, GCR_CL_COHERENCE_OFS(v1)
160 * We're up, cached & coherent. Perform any further required core-level
163 1: jal mips_cps_core_init
167 * Boot any other VPEs within this core that should be online, and
168 * deactivate this VPE if it should be offline.
170 jal mips_cps_boot_vpes
174 lw t1, VPEBOOTCFG_PC(v0)
175 lw gp, VPEBOOTCFG_GP(v0)
176 lw sp, VPEBOOTCFG_SP(v0)
179 END(mips_cps_core_entry)
213 la k0, ejtag_debug_handler
218 LEAF(mips_cps_core_init)
219 #ifdef CONFIG_MIPS_MT
220 /* Check that the core implements the MT ASE */
227 /* Only allow 1 TC per VPE to execute... */
230 /* ...and for the moment only 1 VPE */
236 /* Enter VPE configuration state */
237 1: mfc0 t0, CP0_MVPCONTROL
238 ori t0, t0, MVPCONTROL_VPC
239 mtc0 t0, CP0_MVPCONTROL
241 /* Retrieve the number of VPEs within the core */
242 mfc0 t0, CP0_MVPCONF0
243 srl t0, t0, MVPCONF0_PVPE_SHIFT
244 andi t0, t0, (MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT)
247 /* If there's only 1, we're done */
251 /* Loop through each VPE within this core */
254 1: /* Operate on the appropriate TC */
255 mtc0 t5, CP0_VPECONTROL
258 /* Bind TC to VPE (1:1 TC:VPE mapping) */
261 /* Set exclusive TC, non-active, master */
263 sll t1, t5, VPECONF0_XTC_SHIFT
265 mttc0 t0, CP0_VPECONF0
267 /* Set TC non-active, non-allocatable */
268 mttc0 zero, CP0_TCSTATUS
280 /* Leave VPE configuration state */
281 2: mfc0 t0, CP0_MVPCONTROL
282 xori t0, t0, MVPCONTROL_VPC
283 mtc0 t0, CP0_MVPCONTROL
289 END(mips_cps_core_init)
291 LEAF(mips_cps_boot_vpes)
292 /* Retrieve CM base address */
296 /* Calculate a pointer to this cores struct core_boot_config */
297 lw t0, GCR_CL_ID_OFS(t0)
298 li t1, COREBOOTCFG_SIZE
300 la t1, mips_cps_core_bootcfg
304 /* Calculate this VPEs ID. If the core doesn't support MT use 0 */
308 /* Find the number of VPEs present in the core */
309 mfc0 t1, CP0_MVPCONF0
310 srl t1, t1, MVPCONF0_PVPE_SHIFT
311 andi t1, t1, MVPCONF0_PVPE >> MVPCONF0_PVPE_SHIFT
314 /* Calculate a mask for the VPE ID from EBase.CPUNum */
322 /* Retrieve the VPE ID from EBase.CPUNum */
326 1: /* Calculate a pointer to this VPEs struct vpe_boot_config */
327 li t1, VPEBOOTCFG_SIZE
329 lw t7, COREBOOTCFG_VPECONFIG(t0)
332 #ifdef CONFIG_MIPS_MT
334 /* If the core doesn't support MT then return */
343 1: /* Enter VPE configuration state */
348 1: mfc0 t1, CP0_MVPCONTROL
349 ori t1, t1, MVPCONTROL_VPC
350 mtc0 t1, CP0_MVPCONTROL
353 /* Loop through each VPE */
354 lw t6, COREBOOTCFG_VPEMASK(t0)
358 /* Check whether the VPE should be running. If not, skip it */
363 /* Operate on the appropriate TC */
364 mfc0 t0, CP0_VPECONTROL
365 ori t0, t0, VPECONTROL_TARGTC
366 xori t0, t0, VPECONTROL_TARGTC
368 mtc0 t0, CP0_VPECONTROL
371 /* Skip the VPE if its TC is not halted */
376 /* Calculate a pointer to the VPEs struct vpe_boot_config */
377 li t0, VPEBOOTCFG_SIZE
381 /* Set the TC restart PC */
382 lw t1, VPEBOOTCFG_PC(t0)
383 mttc0 t1, CP0_TCRESTART
385 /* Set the TC stack pointer */
386 lw t1, VPEBOOTCFG_SP(t0)
389 /* Set the TC global pointer */
390 lw t1, VPEBOOTCFG_GP(t0)
393 /* Copy config from this VPE */
397 /* Ensure no software interrupts are pending */
398 mttc0 zero, CP0_CAUSE
399 mttc0 zero, CP0_STATUS
401 /* Set TC active, not interrupt exempt */
402 mftc0 t0, CP0_TCSTATUS
403 li t1, ~TCSTATUS_IXMT
405 ori t0, t0, TCSTATUS_A
406 mttc0 t0, CP0_TCSTATUS
408 /* Clear the TC halt bit */
409 mttc0 zero, CP0_TCHALT
412 mftc0 t0, CP0_VPECONF0
413 ori t0, t0, VPECONF0_VPA
414 mttc0 t0, CP0_VPECONF0
422 /* Leave VPE configuration state */
423 mfc0 t1, CP0_MVPCONTROL
424 xori t1, t1, MVPCONTROL_VPC
425 mtc0 t1, CP0_MVPCONTROL
429 /* Check whether this VPE is meant to be running */
436 /* This VPE should be offline, halt the TC */
445 #endif /* CONFIG_MIPS_MT */
450 END(mips_cps_boot_vpes)
452 #if defined(CONFIG_MIPS_CPS_PM) && defined(CONFIG_CPU_PM)
454 /* Calculate a pointer to this CPUs struct mips_static_suspend_state */
460 la \dest, __per_cpu_offset
463 la \dest, cps_cpu_state
464 addu \dest, \dest, $1
468 LEAF(mips_cps_pm_save)
475 END(mips_cps_pm_save)
477 LEAF(mips_cps_pm_restore)
478 /* Restore CPU state */
480 RESUME_RESTORE_STATIC
481 RESUME_RESTORE_REGS_RETURN
482 END(mips_cps_pm_restore)
484 #endif /* CONFIG_MIPS_CPS_PM && CONFIG_CPU_PM */